我可以知道如何在自定義SimpleAdapter中刪除地圖列表項目後刷新ListView項目嗎?Android:如何在自定義SimpleAdapter中刪除項目時刷新列表
我已經用list.remove(position)成功實現了刪除列表項,但是當我嘗試調用list.notifyAll()函數時,它卻給了我錯誤消息,比如「java.lang.IllegalMonitorStateException:object not locked通過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;
}
};
非常感謝您的幫助。
但它顯示我「不能讓一個靜態引用從類型的非靜態方法notifyDataSetChanged()」 ......你能教我如何解決呢? – user1082138
使用'DeleteAdapter.this.notifyDataSetChanged()'。 – inazaruk
是的!它正在工作!感謝您的幫助^。^ – user1082138