0

I'm wanting to see which tab is selected and execute specific code based on that selection. I've used the following tutorial to create the list with images and the problem is the list items are in separate tabs and the code I followed only sets the images for the first tab.

http://www.debugrelease.com/2013/06/24/android-listview-tutorial-with-images-and-text/

Here's how I've set up the tabs.

        TabHost tabHost = getTabHost();

        //Tab for Students
        TabSpec studentSpec = tabHost.newTabSpec("Students");
        //set the tile and icon
        studentSpec.setIndicator("Students", getResources().getDrawable(R.drawable.icon_students));
        Intent songsIntent = new Intent(this, StudentsTab.class);
        studentSpec.setContent(songsIntent);

        //Tab for Support
        TabSpec supportSpec = tabHost.newTabSpec("Support");
        //set the tile and icon
        supportSpec.setIndicator("Support", getResources().getDrawable(R.drawable.icon_support));
        Intent videosIntent = new Intent(this, SupportTab.class);
        supportSpec.setContent(videosIntent);

        //tabHost.addTab(homeSpec);
        tabHost.addTab(studentSpec);
        tabHost.addTab(supportSpec);

    }

So I have two methods in the Model.java class from the tutorial, each that runs the appropriate icons and text. I need these to be called on a specific tab.

Thank you!

4

2 回答 2

1

As armaan Stranger pointed out, tabs are outdated and you should use actionbar tabs. There is a good sample on how to create swipe tabs on android.developer.

If you still want to use the deprecated (you should not) then you need to implement OnTabChangeListener then you can see which tab is called in public void onTabChanged(String tabId).

于 2013-08-02T04:53:27.583 回答
0

You can use getCurrentTab() that returns index of tab start from 0.

于 2014-01-24T11:09:07.257 回答