java - Getting OnLongClick to work in ListView Android Studio -
java - Getting OnLongClick to work in ListView Android Studio -
i trying onlongclick
on each item of listview android studio not recognise super.oncreatecontextmenu(menu, v, menuinfo);
, super.oncontextitemselected(item);
. when take these out noting works @ all.
inside oncreate have
registerforcontextmenu(getlistview());
then below function have next functions
public void oncreatecontextmenu(contextmenu menu, view v, contextmenu.contextmenuinfo menuinfo) { super.oncreatecontextmenu(menu, v, menuinfo); adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) menuinfo; menu.setheadertitle(madapter.getitem(info.position).tostring()); menu.add(menu.none, context_menu_delete, context_menu_delete, r.string.del_item); } public boolean oncontextitemselected(menuitem item) { adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo(); switch (item.getitemid()) { case context_menu_delete: madapter.remove(info.position); homecoming true; default: homecoming super.oncontextitemselected(item); } homecoming true; }
make sure imports compatibility library , not sdk itself.
java android android-studio
Comments
Post a Comment