android - Recall, onCreateOptionsMenu method (more times) -


i have problem: in class.java have private method (i call in onremotecalllistenercomplete) elaborate data want appear in menu. method not fast , application call oncreateoptionsmenu method before onremotecalllistenercomplete finished.

i have read use void invalidateoptionsmenu() method - invalidate , re-call oncreateoptionsmenu - , append before onremotecalllistenercomplete ended. however, onoptionsitemselected method not re-called.

nb: i'm sorry (terrible) english

the following put code

oncreateoptionsmenu method

@override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.dati_carriera, menu);      sharedpreferences prefs = getpreferences(mode_private);     menuitem item = menu.finditem(r.id.expandablelistview1_checkable);      if(sizevaluecollection>0){         item.setvisible(false);     }else{         boolean value = prefs.getboolean(preference_expandible_list_view, true);             if(value)             item.setchecked(true);         else             item.setchecked(false);     }     return super.oncreateoptionsmenu(menu); } 

onoptionsitemselected method

@override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     sharedpreferences prefs = getpreferences(mode_private);      toast.maketext(this, "onoptionitemselceted", toast.length_long).show();      final expandablelistview tv;     int id=item.getitemid();     switch(id){     case r.id.expandablelistview1_checkable:         tv = (expandablelistview) findviewbyid(r.id.expandablelistview1);         if(item.ischecked()){             item.setchecked(false);             tv.setvisibility(expandablelistview.gone);             editor prefseditor = prefs.edit();             prefseditor.putboolean(preference_expandible_list_view, false);             prefseditor.commit();         }else{             item.setchecked(true);             tv.setvisibility(expandablelistview.visible);             editor prefseditor = prefs.edit();             prefseditor.putboolean(preference_expandible_list_view, true);             prefseditor.commit();         }         return true;     default:         return super.onoptionsitemselected(item);     } } 

onremotecalllistenercomplete

    @override public void onremotecalllistenercomplete(string dati) {     // todo auto-generated method stub      [...]      sizevaluecollection=valuecollection.size();     invalidateoptionsmenu(); } 

sizevaluecollection private int variable initialized -1

try supportinvalidateoptionsmenu() if use activity support package


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -