android 移除多个数组,android listview移除一条数据后造成数组越界异常
在适配器里移除一条数据之后就数组越界异常,代码是这样写的holder.minus.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {int count = data.get(position).getCount();count--;if (count <= 0) {coun
在适配器里移除一条数据之后就数组越界异常,代码是这样写的
holder.minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = data.get(position).getCount();
count--;
if (count <= 0) {
count = 0;
data.remove(data.get(position));
return;
}
holder.count.setText(count + "");
data.get(position).setCount(count);
holder.price.setText((data.get(position).getCommodity_price()) * (data.get(position).getCount()) + "");
ShopFragment.handler.sendEmptyMessage(1);
}
});
解决办法其实很简单
移除数据后立马刷新下适配器就好啦
holder.minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = data.get(position).getCount();
count--;
if (count <= 0) {
count = 0;
data.remove(data.get(position));
notifyDataSetChanged();
return;
}
holder.count.setText(count + "");
data.get(position).setCount(count);
holder.price.setText((data.get(position).getCommodity_price()) * (data.get(position).getCount()) + "");
ShopFragment.handler.sendEmptyMessage(1);
}
});
更多推荐
所有评论(0)