Deleting an android ListView row on LongClick -


i have code data database , display in listview

list<contact> contacts = db2.getallcontacts();         arraylist<string> my_list = new arraylist<>();          (contact cn : contacts) {             string outputt = "id: " + cn.getid() + ", message: " + cn.getmessage() +                     ", time: " + cn.getdate();             my_list.add(outputt);         }          arrayadapter<string> adapter = new arrayadapter<string>                 (this, android.r.layout.simple_list_item_1, my_list);           listview listview = (listview) findviewbyid(r.id.listview);          listview.setadapter(adapter); 

i want delete particular item/row on listview on swipe. how can achieve ?

you can use enhancedlistview. copy the enhancedlistview class linked repo in project. instead of listview, use , enhancedlistview in code. i.e.:

enhancedlistview listview = (enhancedlistview) findviewbyid(r.id.listview);  // set enhancedlistview.ondismisscallback:  listview.setdismisscallback(new de.timroes.android.listview.enhancedlistview.ondismisscallback() {              @override             public enhancedlistview.undoable ondismiss(enhancedlistview listview, final int position) {                  final string item = (string) adapter.getitem(position);                 adapter.remove(position);                 // if you'd user able undo swipe:                 return new enhancedlistview.undoable() {                     @override                     public void undo() {                         adapter.insert(position, item);                     }                 };             }         });  // enable swipe dismiss:  listview.enableswipetodismiss(); 

note: repo not maintained developer anymore in favour of new recyclerview google. can use copying enhancedlistview class in code.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -