Android:如何在自定义 SimpleAdapter 中删除项目时刷新列表

发布于 2024-12-20 03:49:18 字数 1713 浏览 3 评论 0原文

我可以知道在自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆光飞翔i 2024-12-27 03:49:18

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

You should call Adapter's notifyDataSetChanged() function, not notifyAll() on list.

七堇年 2024-12-27 03:49:18

使用

 this.notifyDataSetChange();

Use

 this.notifyDataSetChange();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文