如何在customlistview中维护每个EditText的值 [英] How to maintain value of each EditText in customlistview
本文介绍了如何在customlistview中维护每个EditText的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好,我在维护自定义列表视图中每个EditText的值时遇到问题,例如,旋转屏幕,每个值都消失了, 请帮助我,我应该怎么做,谢谢.
Good Day, I have a problem with maintaining value on each EditText in a custom listview for example I rotate the screen, each value has gone, Please Help me what approach should I do, Thanks in advance.
图片适配器
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;
}
推荐答案
在您的 PSP 模型).
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();
}
});
希望对您有帮助.
这篇关于如何在customlistview中维护每个EditText的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文