当意识到还不允许选择选项卡时,要在 onTabSelected() 中重新选择选项卡,我发现您可以使用以下内容:
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
boolean bOK = true;
if (tab.getPosition() == 1) {
if (!checkReadyToChangeTab()) {
Toast.makeText(activity, "Cannot change tab!", Toast.LENGTH_SHORT).show();
bOK = false;
// reselect tab 0
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
public void run() {
getSupportActionBar().selectTab(getSupportActionBar().getTabAt(0));
}
};
handler.postDelayed(runnable, 10);
}
}
if (bOK) {
ft.replace(R.id.fragment_container, fragment);
}
}