android - FragmentTabHost from Navigation Drawer -
i trying create app navigation drawer using sample navigation drawer app within android studio. first fragment trying create navigation drawer has 3 tabs , i'm trying use fragmenttabhost switch between tabs , load different fragment below each tab.i want user navigate main sections of app navigation drawer , on screens want have sub-level navigation using tabhost. want use 2 level navigation recommended on android developers site here: https://www.google.com/design/spec/patterns/navigation.html#navigation-two-levels
i found examples of how use fragmenttabhost here: http://developer.android.com/reference/android/support/v4/app/fragmenttabhost.html
the first example doesn't work because fragmenttabhost extending fragmentactivity navigation drawer code appears invoke fragments
trying implement second example using nested fragments giving me error following error:
error:(106, 17) error: no suitable method found setup(fragmentactivity,fragmentmanager,int) method tabhost.setup(localactivitymanager) not applicable (actual , formal argument lists differ in length) method tabhost.setup() not applicable (actual , formal argument lists differ in length)
at:
mtabhost.setup(getactivity(), getchildfragmentmanager(), r.layout.fragment_tab_host);
here snippet mainactivity.java:
public class mainactivity extends actionbaractivity implements navigationdrawerfragment.navigationdrawercallbacks{ private navigationdrawerfragment mnavigationdrawerfragment; @override public void onnavigationdraweritemselected(int position) { // update main content replacing fragments fragment fragment = null; switch (position) { case 0: fragment = new fragment_tabhost(); break; default: break; } if (fragment != null) { fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.container, fragment).commit(); // update selected item , title, close drawer } else { log.e("mainactivity", "error in creating fragment"); } } }
here snippet of code fragment_tabhost.java called when click first item in navigation drawer:
import android.app.activity; import android.net.uri; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmenttabhost; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.tabhost; public class fragment_tabhost extends fragment { private tabhost mtabhost; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment mtabhost = new fragmenttabhost(getactivity()); mtabhost.setup(getactivity(), getchildfragmentmanager(), r.layout.fragment_tab_host); mtabhost.addtab(mtabhost.newtabspec("tab1").setindicator("tab1"), tab1.class, null); mtabhost.addtab(mtabhost.newtabspec("tab2").setindicator("tab2"), tab2.class, null); mtabhost.addtab(mtabhost.newtabspec("tab3").setindicator("tab3"), tab3.class, null); return mtabhost; } }
i targeting minimum sdk of api level 15 open better way if 1 exists.
this sample app ships android studio seems aged. recommend use drawerlayout. find official sample google here.
if want full example newest api take @ github sample.
for case classes, draweractivity, tabholderfragment , tabfragment intressting.
Comments
Post a Comment