gpt4 book ai didi

java - onBack按回到主屏幕

转载 作者:行者123 更新时间:2023-12-01 23:12:05 25 4
gpt4 key购买 nike

当我回按时,我希望该选项卡有一个条件,它会在“主页”选项卡上显示,但当我回按时,所有 Activity 都会结束。

这是我的代码。尝试帮助我。

 backpressed = true;

if (results.equals("HOME")) {
mTabHost.setCurrentTab(0);
backpressed = false;
} else if (results.equals("B")) {
mTabHost.setCurrentTab(2);
} else if (results.equals("C")) {
mTabHost.setCurrentTab(3);
} else if (results.equals("D")) {
mTabHost.setCurrentTab(1);
} else if (results.equals("E")) {

singleton.openNewsFeed = true;
mTabHost.setCurrentTab(4);
} else {
singleton.openMessage = true;
mTabHost.setCurrentTab(4);
}

这是我的 onBackPressed

 @Override
public void onBackPressed() {
/*super.onBackPressed();*/

if (backpressed == true) {
Intent intent = new Intent(getApplicationContext(), Dashboard.class);
intent.putExtra("result", "HOME"); // getText() SHOULD NOT be static!!!
startActivity(intent);
}else{
//FINISH
super.onBackPressed();
}

}

最佳答案

这里的条件有误

你应该尝试一下

 backpressed = false;

if (results.equals("HOME")) {
mTabHost.setCurrentTab(0);
backpressed = true;
} else if (results.equals("B")) {
mTabHost.setCurrentTab(2);
} else if (results.equals("C")) {
mTabHost.setCurrentTab(3);
} else if (results.equals("D")) {
mTabHost.setCurrentTab(1);
} else if (results.equals("E")) {

singleton.openNewsFeed = true;
mTabHost.setCurrentTab(4);
} else {
singleton.openMessage = true;
mTabHost.setCurrentTab(4);
}

背面按下

 @Override
public void onBackPressed() {
/*super.onBackPressed();*/

if (backpressed == true) {
Intent intent = new Intent(getApplicationContext(), Dashboard.class);
intent.putExtra("result", "HOME"); // getText() SHOULD NOT be static!!!
startActivity(intent);
}else{
//FINISH
//super.onBackPressed();
mTabHost.setCurrentTab(0);
}

}

关于java - onBack按回到主屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58369172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com