java - AdapterView.AdapterContextMenuInfo is null -
here problem, have architecture of class :
- activity
- fragment
- recyclerview (which has adapter)
- fragment
the adapter:
has class viewholder:
public static class noteviewholder extends recyclerview.viewholder implements view.oncreatecontextmenulistener{ textview notename; public noteviewholder(view itemview) { super(itemview); notename = (textview)itemview.findviewbyid(r.id.note_name); itemview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) {/**/} }); itemview.setoncreatecontextmenulistener(this); } @override public void oncreatecontextmenu(contextmenu contextmenu, view view, contextmenu.contextmenuinfo contextmenuinfo) { contextmenu.setheadertitle("select action"); contextmenu.add(0,666,0,"delete note"); }
}
the fragment
overrrides oncontextitemselected(menuitem item){ //info null adapterview.adaptercontextmenuinfo info = (adapterview.adaptercontextmenuinfo) item.getmenuinfo(); }
it calls
registerforcontextmenu(recyclerview);
the sequence
- i long click on noteviewholder, opens context menu
- i select "delete"
- oncreatecontextmenu called contextmenuinfo == null
- onselectedcontextitem called item.getmenuinfo() == null
how can menuinfo non null?
shoud create myself menu info, , if where?
ps, i've seen post: how create context menu recyclerview , don't see answer this
ps2 i've read this: http://androidheight.blogspot.fr/2015/03/recyclerview-widget-example-in-android.html, , me line new recycleradapter().info = menuinfo;
seems wrong
thank you
you need call registerforcontextmenu()
in activity on recyclerview.
Comments
Post a Comment