开发者

Need help to delete selected item from listview

开发者 https://www.devze.com 2023-03-02 22:41 出处:网络
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.

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消