android 选项卡 Activity 转到上一个选项卡

标签 android tabs

我有一个包含五个选项卡的 Activity 。当我从选项卡 1 转到选项卡 2 或选项卡 3 时,一切看起来都很好。如何以编程方式从选项卡 2 返回到选项卡 1?

    Intent myIntent = new Intent(this, Tab1.class);             
    myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(myIntent);

这不能正常工作,因为它在没有任何选项卡的情况下启动 Activity 1。

从选项卡 1 转到选项卡 2 时,我可以同时看到选项卡 1 和选项卡 2(当前选项卡已激活)。但是当从选项卡 2 转到选项卡 1 时,选项卡 1 和选项卡 2 从 Activity 中消失。什么可能导致这种情况?

最佳答案

这一定会对你有所帮助。

TabHost tabHost =  (TabHost) getParent().findViewById(android.R.id.tabhost);
tabHost.setCurrentTab(1);  

或者你可以引用这个链接

How to programmatically switch tabs using buttonclick in Android

谢谢:)

关于android 选项卡 Activity 转到上一个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11630657/

相关文章:

angularjs - 为什么 jquery-chosen 在 angular-ui 的选项卡内不起作用

java - 看看用户是否点击了后退按钮?

android - 将项目添加到 ListAdapter 会导致异常

android - 等待 TTS/语音识别在 Android 应用程序中完成

php - 如何让 emacs 在 PHP 模式下使用制表符进行缩进?

android如何在我的应用程序中获取如下图所示的选项卡

javascript - 可以通过选项卡选择单选按钮吗?

javascript - angularjs bootstrap ng-repeat 在选项卡内不起作用

android - 使用 OKHttp 创建适当的 MultipartBuilder Http 请求

android - 从 Android 访问信标帧信息