for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
getTabWidget().getChildAt(i).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (getTabHost().getCurrentTabTag().equals(v.getTag()))
{
int nextTab = getTabHost().getCurrentTab();
tabHost.setCurrentTab(prevTab);
tabHost.setCurrentTab(nextTab);
prevTab = nextTab;
}
else
tabHost.setCurrentTabByTag((String) v.getTag());
}
});
}
You need a global variable;
private int prevTab = 1; //any tab except the initial one.
This code works for me. A little ugly thing is you must set same tag for tab and view
For example;
intent = new Intent().setClass(this, AnaSayfa.class);
spec = tabHost.newTabSpec("firstTab").setIndicator(makeTabIndicator(R.drawable.firstTab, "First Tab" , "firstTab"))
.setContent(intent);
tabHost.addTab(spec);
and makeTabIndicator method is like that,
private View makeTabIndicator(int drawable, String text, String viewTag){
View view = LayoutInflater.from(this).inflate(R.layout.tab_layout, null);
ImageView image = (ImageView) view.findViewById(R.id.imageView1);
image.setImageResource(drawable);
image.setAdjustViewBounds(true);
TextView tv = (TextView) view.findViewById(R.id.textView1);
tv.setText(text);
view.setTag(viewTag);
return view;
}