Reputation: 4258
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:
but i don't know how, because this is the first time, that i would like to do this :/
Upvotes: 0
Views: 3112
Reputation: 1575
You can use context menus see 'http://www.javatpoint.com/android-context-menu-example' for reference
Upvotes: 2
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
Reputation: 2770
You can setOnItemLongClickListener()
to the listview and show, a options dialog, and on clicking delete button delete that row.
Upvotes: 0