gpt4 book ai didi

java - 如何维护自定义 ListView 中每个 EditText 的值

转载 作者:行者123 更新时间:2023-11-29 02:58:39 28 4
gpt4 key购买 nike

美好的一天,我在自定义 ListView 中维护每个 EditText 的值时遇到问题,例如我旋转屏幕,每个值都消失了,请帮助我应该采取什么方法,在此先感谢。

enter image description here

图片适配器

    public View getView(int position, View convertView, ViewGroup parent) {
View row;
row = convertView;
final dataHandler handler;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate( R.layout.row_layout,parent, false);
handler = new dataHandler();
handler.pictures = (ImageView) row.findViewById(R.id.pictures);
handler.name = (TextView) row.findViewById(R.id.picturename);
handler.qty= (EditText) row.findViewById(R.id.qty);
handler.add = (Button) row.findViewById(R.id.btnplus);
handler.minus = (Button) row.findViewById(R.id.btnminus);
row.setTag(handler);
}else{
handler = (dataHandler) row.getTag();
}
final PSP psp;
psp =(PSP) this.getItem(position);
Picasso.with(getContext()).load(psp.getPicture()).resize(200, 155).into(handler.pictures);
handler.name.setText(psp.getName() + "\n ₱" + psp.getPrice());
handler.qty.setText("0");
img = psp.getPicture();

handler.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pricex = handler.qty.getText().toString();
int xx = Integer.parseInt(pricex);
int total = xx + 1;
String totalx = Integer.toString(total);
handler.qty.setText(totalx);

map.put("" + handler.name.getText().toString(), " " + handler.qty.getText().toString());
ShowHashMapValue();
}
});

handler.minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pricex = handler.qty.getText().toString();

int xx = Integer.parseInt(pricex);
if(xx > 0 ){
int total = xx-1;
String totalx = Integer.toString(total);
handler.qty.setText(totalx);
map.put("" + handler.name.getText().toString(), " " + handler.qty.getText().toString());


}}
});



return row;
}

最佳答案

添加setQuantitygetQuantity(PSP 模型中的getter-setter 方法)。

    String pricex = psp.getQuanntity();
int xx = Integer.parseInt(pricex);
int total = xx + 1;
String totalx = Integer.toString(total);
handler.qty.setText(totalx);

handler.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//add
psp.setQuantity(yourQuantity++);
notifyDataSetChanged();
}
});

handler.minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//add
psp.setQuantity(yourQuantity--);
notifyDataSetChanged();
}
});

希望对你有帮助

关于java - 如何维护自定义 ListView 中每个 EditText 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36613560/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com