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());
}
});
}
Hai bisogno di un variabile globale;
private int prevTab = 1; //any tab except the initial one.
Questo codice funziona per me. Un po 'brutto è necessario impostare lo stesso tag per la scheda e visualizzare Ad esempio;
intent = new Intent().setClass(this, AnaSayfa.class);
spec = tabHost.newTabSpec("firstTab").setIndicator(makeTabIndicator(R.drawable.firstTab, "First Tab" , "firstTab"))
.setContent(intent);
tabHost.addTab(spec);
e il metodo makeTabIndicator è così,
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;
}
'TabHost.OnTabChangeListener' – st0le
TabHost.onTabChangeListener viene generato solo quando la scheda viene modificata. Ma voglio che l'evento venga attivato anche se si fa clic sull'intestazione della scheda attualmente attiva. È possibile farlo? – Sudar