android - Fragment will not display in 1st attempt, but 2nd time onward it will working fine -


i have navigation drawer activity, can go different different fragments. 2 of fragments need pass value using bundle. did this

//navigation drawer item select switch between different fragment @suppresswarnings({"statementwithemptybody", "constantconditions"}) @override public boolean onnavigationitemselected(@nonnull menuitem item) {      int id = item.getitemid();      if (id == r.id.nav_breakfast) {         fragment fragment = null;         class<category> fragmentclass;         fragmentclass = category.class;         try {             assert fragmentclass != null;             fragment = fragmentclass.newinstance();         } catch (exception e) {             e.printstacktrace();         }         fragmentmanager fragmentmanager = getsupportfragmentmanager();         bundle args = new bundle();         args.putstring("header", "breakfast");         args.putstring("category", "1");         fragment.setarguments(args);         fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit();     } else if (id == r.id.nav_lunch) {         fragment fragment = null;         class<category> fragmentclass;         fragmentclass = category.class;         try {             assert fragmentclass != null;             fragment = fragmentclass.newinstance();         } catch (exception e) {             e.printstacktrace();         }         fragmentmanager fragmentmanager = getsupportfragmentmanager();         bundle args = new bundle();         args.putstring("header", "lunch");         args.putstring("category", "0");         fragment.setarguments(args);         fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit();     } else if (id == r.id.nav_history) {         fragment fragment = null;         class<history> fragmentclass;         fragmentclass = history.class;         try {             assert fragmentclass != null;             fragment = fragmentclass.newinstance();         } catch (exception e) {             e.printstacktrace();         }         fragmentmanager fragmentmanager = getsupportfragmentmanager();         fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit();     }       drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     assert drawer != null;     drawer.closedrawer(gravitycompat.start);      return true; } 

1st 2 fragmetns not displaying when 1st openning app. 3rd 1 working fine. in first 2 fragment recived data like:

 bundle extras = getactivity().getintent().getextras();  if (extras != null) {      header = getarguments().getstring("header");      string subcat = getarguments().getstring("category");      breakfastdata(subcat);  } 

now should do?


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -