1

当我按下我的第二个选项卡时,我会检查 Internet 是否可用,如果没有,我的选择应该返回到上一个选项卡。为此,我正在使用 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);
4

0 回答 0