Get index of selected tab in tabHost

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?

9
задан Jack 27 August 2010 в 10:45
поделиться

1 ответ

Вы на правильном пути, используйте setOnTabChangedListener, чтобы получить выбранную вкладку.

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());
        }       
    });  
...
...
...
26
ответ дан 4 December 2019 в 06:49
поделиться
Другие вопросы по тегам:

Похожие вопросы: