Need help to delete selected item from listview

℡╲_俬逩灬. 提交于 2019-12-12 06:17:51

问题


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


回答1:


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 :-)



来源:https://stackoverflow.com/questions/5881665/need-help-to-delete-selected-item-from-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!