需要帮助删除列表视图中选中的项目 [英] Need help to delete selected item from listview
问题描述
我想删除列表视图中选择的项目;
其实我想从上下文菜单中执行此操作。一切都很好,但我不能删除该项目。
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
推荐答案
我在code这样使用,它可以从列表中删除多个项目
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));
}
}
});
然后,我宣布的删除,就可以对ClickListener方法的一个按钮,它调用从数据库中code(根据你的情况可能是ArrayList的或数组)以删除ArrayList中选择的项目 select_archived_party。希望它可以帮助: - )
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 :-)
这篇关于需要帮助删除列表视图中选中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!