需要帮助从列表视图中删除所选项目

发布于 2024-11-05 14:02:53 字数 89 浏览 3 评论 0原文

我想从列表视图中删除选定的项目; 实际上我想从上下文菜单中执行此操作。一切都很顺利,但我无法删除该项目。

请给我一些从列表视图中删除项目的建议或示例

I want to delete a selected item from the list view;
actually I want to perform this operation from the context menu. Everything is going fine but I'm not able to delete that item.

Please give me some suggestions or examples to remove item from the listview

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

染年凉城似染瑾 2024-11-12 14:02:53

我在我的代码中使用了这样的方法,它可以从列表中删除多个项目

ListView lv_ArchivePartylist;

 ArrayList<Parties> select_archived_party;

lv_ArchivePartylist = (ListView)findViewById(R.id.archive_ListView01);
        lv_ArchivePartylist.setOnItemClickListener(new OnItemClickListener()
            {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
                // TODO Auto-generated method stub
                if(view.findViewById(R.id.img_chkbox_archive).getVisibility()==TextView.GONE)
                {
                    view.findViewById(R.id.img_chkbox_archive).setVisibility(TextView.VISIBLE);
                    Toast.makeText(ctx_archive, "Name="+archived_parties.get(position).getPartyTitle(), Toast.LENGTH_SHORT).show();
select_archived_party.add(archived_parties.get(position));
}
}

});

然后我声明了一个“删除”按钮,并在其 On ClickListener 方法上调用数据库中的代码(在您的情况下,它可能是 Arraylist或数组)删除在Arraylist“select_archived_pa​​rty”中选择的项目。希望它有帮助:-)

I have used like this in my code, it can delete multiple items from the list

ListView lv_ArchivePartylist;

 ArrayList<Parties> select_archived_party;

lv_ArchivePartylist = (ListView)findViewById(R.id.archive_ListView01);
        lv_ArchivePartylist.setOnItemClickListener(new OnItemClickListener()
            {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
                // TODO Auto-generated method stub
                if(view.findViewById(R.id.img_chkbox_archive).getVisibility()==TextView.GONE)
                {
                    view.findViewById(R.id.img_chkbox_archive).setVisibility(TextView.VISIBLE);
                    Toast.makeText(ctx_archive, "Name="+archived_parties.get(position).getPartyTitle(), Toast.LENGTH_SHORT).show();
select_archived_party.add(archived_parties.get(position));
}
}

});

Then I've declared one button of "Delete" and on it's On ClickListener method, it calls the code from the database(In your case it may be Arraylist or array) to delete the items selected in Arraylist "select_archived_party". Hope it helps :-)

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