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;
This code works for me. A bit ugly thing, you have to set the same tag for the 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 the makeTabIndicator method is similar to this,
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; }
efeyc
source share