Trombone0904
Trombone0904

Reputation: 4258

android long press to show menu with delete action

i have an android app with a custom list view. i get the data of my local sql database. now i would like add a function, to delete any items of my list view / database.

i would like to realize a long press on any row and show a menu like this where i can chose the delete option:

enter image description here

but i don't know how, because this is the first time, that i would like to do this :/

Upvotes: 0

Views: 3112

Answers (3)

Srikanth
Srikanth

Reputation: 1575

You can use context menus see 'http://www.javatpoint.com/android-context-menu-example' for reference

Upvotes: 2

Jas
Jas

Reputation: 3212

Try this: Try this:

ListView lv = getListView();
            lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){ 
                   @Override 
                   public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) 
                  { 
                    //Your code to show the menu
                  } 
             }); 

Upvotes: 0

Nigam Patro
Nigam Patro

Reputation: 2770

You can setOnItemLongClickListener() to the listview and show, a options dialog, and on clicking delete button delete that row.

Upvotes: 0

Related Questions