android - Does onCreate() called after commit()? -
private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { selectitem(position); } }
private void selectitem(int position) { fragment fragment = new planetfragment(); bundle args = new bundle(); args.putint(planetfragment.arg_planet_number, position); fragment.setarguments(args); fragmentmanager fragmentmanager = getfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit(); mdrawerlist.setitemchecked(position, true); settitle(mplanettitles[position]); mdrawertitle=mplanettitles[position]; mdrawerlayout.closedrawers(); }
my app demo drawer.the 8 planet drawernavigation demo.when click item of listview
shows on drawer,the planet picture on fragment changes.
here confusion:
i think oncreate
, oncreateview
method of fragment
called subsequence "fragmentmanager.begintransaction().replace(r.id.content_frame, fragment).commit();
".
but actually,they called after onitemclick()
finished. why? in advance.
if read documentation of commit method says:
schedules commit of transaction. commit not happen immediately; scheduled work on main thread done next time thread ready.
since selectitem on main thread, commit won't happen until after selectitem returns (but not right after!).
Comments
Post a Comment