android - Drawer Menu and Tabs working together -
i want implement bottom tabs fragment tab host , drawer menu in action bar activity. tabs or drawer menu item open same fragment.
so can 1 me out ..
my code as..
@override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.menu_main, menu); menuitem item = menu.finditem(r.id.action_settings); item.setvisible(false); return true; } @override public boolean onoptionsitemselected(menuitem item) { if (mdrawertoggle.onoptionsitemselected(item)) { return true; } return super.onoptionsitemselected(item); } private void selectitemfromdrawer(final int position) { fragment fragment = null; switch (position) { case 0: fragment = new search(); // mtabhost.setcurrenttab(0); break; case 1: fragment = new featured(); // mtabhost.setcurrenttab(1); break; case 2: fragment = new saved(); // mtabhost.setcurrenttab(2); break; case 3: fragment = new popular(); // mtabhost.setcurrenttab(3); break; case 4: break; default: break; } if (fragment != null) { fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.maincontent, fragment).commit(); mdrawerlist.setitemchecked(position, true); if (position == 0) { getsupportactionbar().settitle("miptags"); } else { getsupportactionbar().settitle(menuitem[position]); } // close drawer mdrawerlayout.closedrawer(mdrawerpane); } else { log.e("mainactivity", "error in creating fragment"); } } private void initview() { mtabhost = new fragmenttabhost(this); mtabhost = (fragmenttabhost) findviewbyid(android.r.id.tabhost); mtabhost.setup(getapplicationcontext(), getsupportfragmentmanager(), r.id.maincontent); mtabhost.addtab( mtabhost.newtabspec("tab1").setindicator(null, getresources().getdrawable(r.drawable.arrow_down)),search.class, null); mtabhost.addtab( mtabhost.newtabspec("tab2").setindicator(null, getresources().getdrawable(r.drawable.arrow_down)), featured.class, null); mtabhost.addtab( mtabhost.newtabspec("tab3").setindicator(null, getresources().getdrawable(r.drawable.arrow_down)), saved.class, null); mtabhost.addtab( mtabhost.newtabspec("tab4").setindicator(null, getresources().getdrawable(r.drawable.arrow_down)), popular.class, null); // mtabhost.addtab( // mtabhost.newtabspec("tab5").setindicator(null, getresources().getdrawable(r.drawable.arrow_down)), null, null); mtabhost.setontabchangedlistener(new tabhost.ontabchangelistener() { @override public void ontabchanged(string tabid) { int = mtabhost.getcurrenttab(); selectitemfromdrawer(i); } }); }
Comments
Post a Comment