gpt4 book ai didi

安卓 : How to Refresh list upon item deletion in customized SimpleAdapter

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:33:54 25 4
gpt4 key购买 nike

我可以知道在自定义 SimpleAdapter 中删除 map 列表项后如何刷新 ListView 项吗?

我已经成功地使用 list.remove(position) 实现了删除列表项,但是当我尝试调用 list.notifyAll() 函数时,它给了我类似“java.lang.IllegalMonitorStateException: object not locked by notifyAll() 之前的线程”。

我希望你能帮助我。这是自定义 SimpleAdapter 的代码。

public class DeleteAdapter extends SimpleAdapter {

Context context;
List<? extends Map<String, ?>> list;
int resource;
String[] from;
int[] to;

public FDeleteAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);

this.context = context;
this.list = data;
this.resource = resource;
this.from = from;
this.to = to;
// TODO Auto-generated constructor stub
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

final View row = super.getView(position, convertView, parent);

final Button delete = (Button) row.findViewById(R.id.deletebut);
final TextView title = (TextView) row.findViewById(R.id.label);

delete.setOnClickListener(new OnClickListener() {

public void onClick(View view) {

deleteDialog xdialog = new deleteDialog(context, "Delete? ", position) {

@Override
public boolean onOkClicked() {

list.remove(position);
list.notifyAll();

return true;
}
};
xdialog.show();
}
});

return row;
}
};

预先感谢您的帮助。

最佳答案

您应该调用 Adapter 的 notifyDataSetChanged()函数,而不是列表中的 notifyAll()

关于安卓 : How to Refresh list upon item deletion in customized SimpleAdapter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8390657/

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