0

I checked one of the solution which asks to use .setIndicator(View view) and add your Tab title and icon in your layout file. But I want to add dynamically FragmentTabHost along with setting its icons. So can anyone answer how to use .setIndicator(View view) with an example of adding say 3 tabs dynamically?

public class MainActivity extends ActionBarActivity {

    private FragmentTabHost mTabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

        Drawable icon = getResources().getDrawable(R.drawable.icon);
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab 1", icon), FragmentTab.class, null);
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Can you please share me the link of the question which is similar to mine? – user4651598 Mar 10 '15 at 13:18
  • I am trying to add FragmentTabHost in a class which extends ActionBarActivity. Is it a proper way of using FragmentTabHost or it has to go in class which extends FragmentActivity. – user4651598 Mar 10 '15 at 13:23

0 Answers0