获取tabHost所选标签的索引 [英] Get index of selected tab in tabHost

查看:182
本文介绍了获取tabHost所选标签的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储的onSaveInstanceState当前选择的选项卡的索引这样我就可以恢复。然而,getCurrentTab apparantely给我回我以前的etTabHost()。newTabSpec,我觉得这有点不可思议,因为文件说,它返回一个int和setCurrentTab也正在采取一个int字符串。 有谁知道我怎样才能让我的当前选择的选项卡的索引,所以我能恢复呢?

I'm trying to store the index of the currently selected tab in onSaveInstanceState so I can restore it. However the getCurrentTab apparantely gives me back the String I used in the etTabHost().newTabSpec, which I find a bit weird since the documentation says it returns an int and setCurrentTab also taking an int. Does anyone know how I can get the index of my currently selected tab so I can restore it?

推荐答案

你是在正确的方式,使用 setOnTabChangedListener 来让你选择的标签。

you are on the right way, use setOnTabChangedListener to get your selected tab.

    public class MainActivity extends TabActivity {   
            static TabHost mytabs;

        mytabs = getTabHost();
            mytabs.setOnTabChangedListener(new OnTabChangeListener() {
                @Override
                public void onTabChanged(String arg0) {         
                    Log.i("***Selected Tab", "Im currently in tab with index::" + mytabs.getCurrentTab());
                }       
            });  
...
...
...

这篇关于获取tabHost所选标签的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆