gpt4 book ai didi

当我删除我唯一的一个记录项时,Android Listview Adapter 不更新/刷新 UI

转载 作者:行者123 更新时间:2023-11-30 02:17:15 25 4
gpt4 key购买 nike

为什么我的 ListView 在我只从我的适配器中删除一个项目时没有更新它的用户界面它保留了它的当前项目显示但是记录已经从我的列表适配器中删除了..?

当从我的适配器中保留多个记录时,我的删除项正在运行,但是当我删除所有项时,我保留了我从 UI 中删除的最后一项。

这是我尝试刷新 UI 但仍然无法正常工作的代码...我正在使用 SimpleAdapter

case PaymentModeCollection.CHECK:
//deletePaymentMode(arrListSet , paymentIdentity);
deletePaymentMode(arrCheck , paymentIdentity);
//checkEditOrAdd = true;
//arrCheck.remove(0);
myAdapter.notifyDataSetChanged();
//listView.refreshDrawableState();
//listView.invalidate();
//onPause();
//onResume();
break;





public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
super(context, items, resource, from, to);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
//if(!(view == null)){
view.setBackgroundColor(colors[colorPos]);
//}
return view;
}

Here is my deletePaymentMode

    protected  static void deletePaymentMode(ArrayList<?> containerSetPaymentMode,String reference){//Set<ArrayList<?>> containerSetPaymentMode
/*
for(int i = 0; i <= containerSetPaymentMode.size() -1; i++){
if(containerSetPaymentMode.get(i) instanceof Cash){


}
if (containerSetPaymentMode.get(i) instanceof Check) {
Check tempCheck = (Check) containerSetPaymentMode.get(i);
if(tempCheck.getxCheckNo().contentEquals(reference)){
Log.d(TAG, "ITEM TO BE DELETE FOUND");
arrCheck.remove(i);
//break;
}
}
}
*/



Iterator<?> ia = containerSetPaymentMode.iterator();



while (ia.hasNext()) {
Object paymentObject = ia.next();


if (paymentObject instanceof Cash) {
ArrayList<Cash> tempArr = (ArrayList<Cash>) paymentObject;


} else if (paymentObject instanceof Check) {
Check tempCheck = (Check) paymentObject;
if(tempCheck.getxCheckNo().contentEquals(reference)){
ia.remove();
break;
}

最佳答案

我不知道你的 deletePaymentMode() 是做什么的,但你应该始终在你的列表上进行更改(添加、删除、更新),该列表包含你的 ListView 项目:

myListViewItems.remove(itemToRemove);
myAdapter.notifyDataSetChanged();

这应该足以删除该项目。

关于当我删除我唯一的一个记录项时,Android Listview Adapter 不更新/刷新 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29094341/

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