获取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());
                }       
            });  
...
...
...