Question

Here my code

View view = getLocalActivityManager().startActivity("recently_viewd", 
                        new Intent(context,Job_Description.class)
                  .putExtra("line", result)
                    .putExtra("limit",0)
                    .putExtra("Alert", false)
                    .putExtra("str_Descrption",edit_Jobdesc.getText().toString().trim())
                    .putExtra("str_location", edit_JobLoc.getText().toString().trim()).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                        .getDecorView();

                setContentView(view);

TabActiviy.class

public class Tab_Bar extends TabActivity  {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);
    setTabs() ;
}
 void setTabs()
{
    addTab("My Profile", R.drawable.home_normal, MyProfile.class);
    addTab("Search", R.drawable.search_normal, JobSearch.class);

    addTab("Saved Jobs", R.drawable.starred, Saved_jobs.class);
    addTab("Job Alert", R.drawable.job_match, JobAlert.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(1);

}

}

I am using this code to open new activity inside a TabHost. Activity opened but Tabhost not appearing

Please Help me how i can fix this problem

Thanks in Advance

Was it helpful?

Solution

 public class Tab_Bar extends TabActivity  {
  TabHost tabHost;
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
tabHost = getTabHost();
tabHost.setup();
setTabs() ;
}
 void setTabs()
{
addTab("My Profile", R.drawable.home_normal, MyProfile.class);
addTab("Search", R.drawable.search_normal, JobSearch.class);

addTab("Saved Jobs", R.drawable.starred, Saved_jobs.class);
addTab("Job Alert", R.drawable.job_match, JobAlert.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{

Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);

spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);

 }

 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top