当我按下第二个标签时,我会检查互联网是否可用,如果没有,我的选择应该返回到上一个标签。要做到这一点,我正在使用tab.select();但它不起作用,有人可以帮助我? 我不知道是否重要,但这段代码在onCreate方法中。
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
final Tab myFiles = actionBar.newTab();
myFiles.setText("Meus Arquivos");
myFiles.setTabListener(new TabListener() {
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
FilesFragment fragment = (FilesFragment) getFragmentManager().findFragmentById(R.id.files_frag);
fragment.loadView();
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
});
actionBar.addTab(myFiles, 0);
Tab downloads = actionBar.newTab();
downloads.setText("Downloads");
downloads.setTabListener(new TabListener() {
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (AndroidUtil.isNetworkAvaliable(getApplicationContext())) {
//Some Code
} else {
Log.d(Constants.MAIN_VIEW_ACTIVITY, "----------------");
Log.d(Constants.MAIN_VIEW_ACTIVITY, "Internet não disponível");
Log.d(Constants.MAIN_VIEW_ACTIVITY, "----------------");
DialogsUtil
.showDialogError(MainViewActivity.this, Constants.ERRO, Constants.NO_SUCH_INTERNET_FOUND);
myFiles.select();
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
});
actionBar.addTab(downloads, 1);