且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Android的列表视图中删除项目

更新时间:2022-11-08 08:51:58

我已经用这样的在我的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_pa​​rty。 希望它可以帮助: - )

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