java - AdapterView.AdapterContextMenuInfo is null -


here problem, have architecture of class :

  • activity
    • fragment
      • recyclerview (which has adapter)

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

  1. i long click on noteviewholder, opens context menu
  2. i select "delete"
  3. oncreatecontextmenu called contextmenuinfo == null
  4. 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

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -