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());
}
});
}
Bạn cần biến toàn cầu;
private int prevTab = 1; //any tab except the initial one.
Mã này phù hợp với tôi. Một điều xấu xí là bạn phải đặt cùng một thẻ cho tab và xem Ví dụ;
intent = new Intent().setClass(this, AnaSayfa.class);
spec = tabHost.newTabSpec("firstTab").setIndicator(makeTabIndicator(R.drawable.firstTab, "First Tab" , "firstTab"))
.setContent(intent);
tabHost.addTab(spec);
và phương pháp makeTabIndicator là như thế,
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 chỉ được kích hoạt khi tab được thay đổi. Nhưng tôi muốn sự kiện được kích hoạt, ngay cả khi tiêu đề tab của tab hiện đang hoạt động được nhấp. Có thể thực hiện điều đó không? – Sudar