android - LayoutTransition causes Fragment to not show up the second time is created -


i have activity implements method:

public void pushfragment(myfragment fragment) {     stack.add(fragment);     fragmentmanager fragmentmanager = getfragmentmanager();     fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction();     fragmenttransaction.replace(r.id.main_frame_layout, fragment);     fragmenttransaction.addtobackstack(null);     fragmenttransaction.commit();     settitle(fragment.gettitle(this)); } 

in fragment, have listview onitemclicklistener:

getappactivity().pushfragment(anotherfragment); 

the anotherfragment oncreateview method:

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {      sethasoptionsmenu(true);      layouttransition t = new layouttransition();     container.setlayouttransition(t);      view rootview = inflater.inflate(r.layout.another_layout, container, false);      final viewgroup vg = (viewgroup)rootview.findviewbyid(r.id.avatar_image_layout);     vg.getlayouttransition().enabletransitiontype(layouttransition.changing);      // stuff      return rootview; } 

on api level >= 19 works. on api 18 , 17 (i didn't test on api 16), first time click on listview item works. go , click time on item. time fragment created, onactivitycreated , oncreateview etc called, fragment isn't displayed.

edit 1: commenting random stuff, i've found out problem is:

layouttransition t = new layouttransition(); container.setlayouttransition(t); 

commenting these 2 lines solves problem, don't know why , loose animation...

this may vary among apis, possible fragmenttransaction isn't applied instantly after calling commit() (info).

according fragmenttransaction.java, commit() method states that:

 * schedules commit of transaction.  commit  * not happen immediately; scheduled work on main thread  * done next time thread ready. 

in order make happening immediately, after commit() method, call fragmentmanager.java's executependingtransactions() (more info):

 * after {@link fragmenttransaction} committed  * {@link fragmenttransaction#commit fragmenttransaction.commit()},  * scheduled executed asynchronously on process's main thread.  * if want executing such pending operations,  * can call function (only main thread) so.  note  * callbacks , other related behavior done within  * call, careful called from. 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -