java - Android - Fragment 2 Displaying back the main fragment with Activity -


from main fragment opened videoplayerfragment, in videoplayerfragment when press button should go parent fragment.

collectiondemoactivity{  class launchpadsectionfragment extends listfragments{  public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);  string fragmaingroups = "maingroups";                       fragment fragment1 = new videoplayerfragment();                      fragmenttransaction transaction = getchildfragmentmanager().begintransaction();                     transaction.replace(r.id.contentfragment, fragment1, fragmaingroups );                     transaction.addtobackstack(fragmaingroups);                     transaction.commit();         }    } } 

external class

videoplayerfragment.java

class videoplayerfragment extends listfragment{

            @override     public view oncreateview(layoutinflater inflater, viewgroup container,                     bundle savedinstancestate) {                              string groups = "groups";                              fragment fragment1 = new collectiondemoactivity.launchpadsectionfragment();                              fragmenttransaction transaction = getchildfragmentmanager().begintransaction();                             transaction.replace(r.layout.load_main_groups_activty, fragment1, groups);                             transaction.addtobackstack(groups);                             transaction.commit();                } 

}

i have use code below open previous fragment backstack using fragment tag.

string fragmaingroups = "maingroups";                             string groups = "groups";                              fragment fragment = (fragment) getfragmentmanager().findfragmentbytag(fragmaingroups);                                                                             if (fragment != null) // null if not instantiated yet                             {                                 if (fragment.getview() != null) {                                     // pop backstack on childmanager if there any. if not, close activity normal.                                     if (!fragment.getfragmentmanager().popbackstackimmediate()) {                                         fragment.getfragmentmanager().popbackstack();                                         //getactivity().finish();                                     }                                 }                             } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -