开发者

Remove item from the listview in Android

开发者 https://www.devze.com 2023-03-01 04:20 出处:网络
I want to delete the item from the listview my code is for listview this.lv1.setAdapter(new ArrayAdapter<String>(FindFilesByType.this, android.R.layout.test_list_item,Ringtones));

I want to delete the item from the listview

my code is for listview

this.lv1.setAdapter(new ArrayAdapter<String>(FindFilesByType.this, android.R.layout.test_list_item,Ringtones));
//          setListAdapter(new ArrayAdapter<String>(FindFilesByType.this, R.layout.main,
//                  Ringtones));
//          
            this.lv1.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onIte开发者_运维百科mClick(AdapterView<?> aView, View v,
                        int position, long id) {
                    currentPosition = position;
                    playRingtone(DIRECTORY+Ringtones.get(position));
                    Toast.makeText(FindFilesByType.this, "postion  "+DIRECTORY+Ringtones.get(position), Toast.LENGTH_LONG).show();
                GlobalVariable.SetstrEmail(DIRECTORY+Ringtones.get(position));
                GlobalVariable.SetcurrentPosition(position);
                }
            });

now how can i delete selected item from it?


may this help android:how to Reload the ArrayAdapater Class in Check/uncheck event of ListView's Chekbox?


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

精彩评论

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

关注公众号