json - Have Android Options Menu wait until return from Web Request -
i calling endpoint pull in json. want activity wait set options menu because want star icon appear full if key-value returns true web service , vice versa. i've tried programming onprepareoptionsmenu() because response on separate thread loads default of toggle icons.
and pointers helpful!
@override public boolean onprepareoptionsmenu(menu menu){ if(isfavorite){ menu.removeitem(r.id.action_non_favorite); menu.add(101, r.id.action_favorite, 0, "true"); }else{ menu.removeitem(r.id.action_favorite); menu.add(101, r.id.action_non_favorite, 0, "false"); } return super.onprepareoptionsmenu(menu); } and here request:
private void senddetailrequest(string urlrequest, final person contact) { jsonobjectrequest objectrequest1 = new jsonobjectrequest(request.method.get, urlrequest, null,new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { string jsonstring = response.tostring(); gson gson = new gsonbuilder().create(); person.persondetail persondetail = gson.fromjson(jsonstring, person.persondetail.class); contact.setcontactdetails(persondetail); isfavorite = persondetail.favorite; //prepareoptionsmenu(r.menu.menu_main); buildpage(contact); } }, new response.errorlistener(){ @override public void onerrorresponse(volleyerror error) { toast.maketext(contactdetails.this, error.getmessage(), toast.length_long).show(); } }); requestqueue requestqueue = volley.newrequestqueue(this); requestqueue.add(objectrequest1); }
i want star icon appear full if key-value returns true web service , vice versa
step #1: create menu normally. however, have android:visible="false" on <item> star.
step #2: in oncreateoptionsmenu(), after using menuinflater inflate menu, call finditem() on menu, passing in id of star item. hold onto menuitem in field of activity or fragment.
step #3: when web service call completes, on main application thread, if needed, call setvisible(true) on menuitem, make star visible user.
iow, not try delay creation of action bar items, not work well. instead, make items visible , invisible needed.
Comments
Post a Comment