5

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

我已经使用 list.remove(position) 成功实现了删除列表项,但是当我尝试调用 list.notifyAll() 函数时,它给了我类似“ java.lang.IllegalMonitorStateException: object not locked by thread before 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;
    }
};

预先感谢您的帮助。

4

2 回答 2

5

您应该调用适配器的notifyDataSetChanged()功能,而不是notifyAll()在列表中。

于 2011-12-05T19:30:31.990 回答
0

采用

 this.notifyDataSetChange();
于 2011-12-05T19:30:45.050 回答