我在tabhost TA1,TA2,TA3,TA4中有四个tabpec,其中我将当前标签设置为TA2,我分别为四个标签A1,A2,A3和A4设置了四个不同的活动,活动A1设置为TA1和等等,然后活动A1打开新活动B1,当我从活动B1按下按钮时,标签应设置为TA1而不是默认TA2,如何在标签主机中实现上述任务,我试图将标签的当前索引存储到共享首选项和onResume我从共享首选项中读取当前选项卡的int值,但这样我无法完成上述任务,如果有人知道最佳解决方案,请告诉我。
答案 0 :(得分:1)
您可以覆盖此功能以检查设备的后退按钮。
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
// implement your Tab move code from one tab to another.
}
return super.onKeyDown(keyCode, event);
}
答案 1 :(得分:1)
Hi Friends i resolved my issue by passing value through intent to main tab activity, here below is sample code,Set this code lines to child activity of tab that means if i relate to above question child activity is "B1",
Intent homeIntent = new Intent(SelectFetchee.this, Home.class);
homeIntent.putExtra("tabvalue", "2");
startActivity(homeIntent);
Then in main activity that have tabhost in which i collect the string
String crntTab = getIntent().getStringExtra("tabvalue");
if (crntTab == null) {
tabHost.setCurrentTab(2);
} else if (crntTab.toString().equals("4")) {
tabHost.setCurrentTab(4);
} else if (crntTab.toString().equals("2")) {
tabHost.setCurrentTab(2);
} else if (crntTab.toString().equals("3")) {
tabHost.setCurrentTab(3);
} else if (crntTab.toString().equals("0")) {
tabHost.setCurrentTab(0);
} else if (crntTab.toString().equals("1")) {
tabHost.setCurrentTab(1);
}
答案 2 :(得分:0)
Reena你应该在你的标签Activity中使用处理程序并在活动B上发送一条消息,然后按回按钮,当你按下时会按下一条消息将发送到Tab Activity并在Handle消息上处理你可以将currentTab设置为Activity TA1。
在TAbActivity中使用此处理程序。
static Handler mHandler;
和onCreate
tabHost.setCurrentTab(1); //For TA2
setTabColor(tabHost);
mHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
super.handleMessage(msg);
if (msg.what == 0)
{
tabHost.setCurrentTab(0);//for TA1
}
}
};
法案B的OnBackPress使用此
Message msgtab=HomeTab.mHandler.obtainMessage();
msgtab.what=0;
HomeTab.mHandler.sendMessage(msgtab);