Need Android tabhost back press navigation -


friend's, implemented tabhost in application,i have 3 tabs defined in activity tab1,tab2,tab3...here have problem navigate tab3 tab1 @ onkey pressed event ,how can reach tab1 tab3 , tab2,i tried using overided keyback pressed,but times it's not responding navigate.without overriding onkey pressed exits application.

here code

tabhost= gettabhost();          tabhost.addtab(tabhost.newtabspec("tab1").setcontent(                 new intent(this, dealcities.class)).setindicator(preparetabview("deals",r.drawable.test)));          tabhost.addtab(tabhost.newtabspec("tab2").setcontent(new intent(this, dbserveractivity.class))                         .setindicator(preparetabview("my quaddeals",r.drawable.mydeal)));          tabhost.addtab(tabhost.newtabspec("tab3").setcontent(new intent(this, account.class))                 .setindicator(preparetabview("my account",r.drawable.img_myaccount))); 

here tabhost defined in 1 class , tabhost object being static one,

here code tab2 pressed event has follows,

 @override     public boolean onkeydown(int keycode, keyevent event) {         if (keycode == keyevent.keycode_back && event.getrepeatcount() == 0) {              try {                //              userdeallist.setvisibility(view.gone);               //              logalerttable.setvisibility(view.gone); //              dealtype.setvisibility(view.gone); //              mydealback=1; //              quadmain.tabhost.setcurrenttab(0);                   intent = new intent();                 i.setclass(dbserveractivity.this, quadmain.class);                 i.setflags(intent.flag_activity_clear_top);                 i.addflags(intent.flag_activity_new_task);                 startactivity(i);              } catch (exception e) {              }             return true;         }          return super.onkeydown(keycode, event);     } 

it works fine , it's not working..

thanks in advance.

check out manual http://knightswhocode.com/wordpress/?p=46 - teaches how use tabhost. unfortunately default onkeybackpressed event go previous activity , have 1 main tabhost activity quits. suggest overriding key pressed , use following method:

@override public boolean onkeydown(int keycode, keyevent event) {     if (keycode == keyevent.keycode_back) {         yourparentactivity parentactivity;         parentactivity = (yourparentactivity) this.getparent();         parentactivity.switchtab(indextabtoswitchto);         return true;     }     return super.onkeydown(keycode, event);  } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -