我从服务器更新数据并使用ArrayAdapter放置editext。但我正在使用加号(p)和减号(m)按钮进行更新,请参阅
图片。但无法更新。知道怎么做吗?
For Plus:
holder.imgPlus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int currentQty = Integer.parseInt(newDataItems.get(position).qty.toString());
for (int i = 0; i < listEdit.size(); i++) {
if (position==i)) {
int finalQty = currentQty + 1;
holder.etShoppingCartQty.setText(""+finalQty);
//listEdit.get(i).setText("" + finalQty);
}
}
}
});
对于MinusButton听众:
int finalQty = currentQty - 1
和自动更新总值。每当点击加号和减号按钮时。
答案 0 :(得分:0)
请按照以下步骤操作:
根据您的代码进行更新:
holder.imgPlus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int currentQty = Integer.parseInt(newDataItems.get(position).qty.toString());
int finalQty = currentQty + 1;
//holder.etShoppingCartQty.setText(""+finalQty);
newDataItems.get(position).setQty(finalQty);
notifyDataSetChanged();
}
});
答案 1 :(得分:0)
在适配器中,在绑定到itemview(获取视图)时将侦听器设置为按钮。
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null){
...inflate
}
//I love ViewHolder pattern, you can not use it
final ViewHolder vh = new ViewHolder(vh);
vh.plus.setOnClickListener(new OnCLickListaner(){
@Override
public void onClick(View v){
//as your example
int currentQty = Integer.parseInt(newDataItems.get(position).qty.toString());
currentQty++;
//...update data (qty), do work to save data changes in model
notifyDataSetChanged();
// or vh.editText.setText("" + currentQty); if you no need to update data
}
});
return view;
}
答案 2 :(得分:0)
使用小调整发布您自己的代码:)
holder.imgPlus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int currentQty = Integer.parseInt(newDataItems.get(position).qty.toString());
for (int i = 0; i < listEdit.size(); i++) {
if (position==i)) {
int finalQty = currentQty + 1;
holder.etShoppingCartQty.setText(""+finalQty);
// Uncommenting below line
listEdit.get(i).setText("" + finalQty);
}
}
// To notify adapter that data set has been changed
notifyDataSetChanged();
}
});