Android:如何在自定义 SimpleAdapter 中删除项目时刷新列表
我可以知道在自定义 SimpleAdapter 中删除地图列表项后如何刷新 ListView 项吗?
我已经成功使用 list.remove(position) 实现了删除列表项,但是当我尝试调用 list.notifyAll() 函数时,它给了我错误消息,如“ java.lang.IllegalMonitorStateException:对象在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;
}
};
预先感谢您的帮助。
May i know how to refresh the ListView item after i have remove a map list item in customized SimpleAdapter ?
I have successfully implement the delete list item with list.remove(position), but when I have tried to called list.notifyAll() function but it gave me error message like " java.lang.IllegalMonitorStateException: object not locked by thread before notifyAll()".
I hope you can help me. Here is the code for custom 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;
}
};
Thank you in advance for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该调用适配器的
notifyDataSetChanged()
函数,而不是列表中的notifyAll()
。You should call Adapter's
notifyDataSetChanged()
function, notnotifyAll()
on list.使用
Use