android tabwidget need help

孤街醉人 提交于 2019-12-11 22:41:37

问题


hello i am creating an application i've created tabbar from pressing the first tab i am downloading a file and into second tab it lists all the downloaded files..i am downloading file using the asyncTask.. i want to do is,after pressing the button for the downloading file i want to show 2nd tab open that is the list of the all downloaded files how it can be possible ? this is my testclass.java that extends the TabActivity

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maiin);
        final TabHost tabHost = (TabHost) getTabHost();
        tabHost.addTab(createTab(activity1name.class, "Welcome",
                "Welcome", R.drawable.tab_icon_events));
        tabHost.addTab(createTab(activity2name.class, ".Mp3List", ".Mp3List",
                R.drawable.tab_icon_pitchforkfm));
        tabHost.addTab(createTab(AboutUs.class, "AboutUs", "AboutUs",
                R.drawable.tab_icon_home));
        tabHost.addTab(createTab(ExtraInfromation.class, "Extra", "Extra",
                R.drawable.tab_icon_tv));
        tabHost.setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;
    }
    private TabSpec createTab(final Class<?> intentClass, final String tag,
            final String title, final int drawable) {
        final Intent intent = new Intent().setClass(this, intentClass);

        final View tab = LayoutInflater.from(getTabHost().getContext())
                .inflate(R.layout.tab, null);
        ((TextView) tab.findViewById(R.id.tab_text)).setText(title);
        ((ImageView) tab.findViewById(R.id.tab_icon))
                .setImageResource(drawable);
        return getTabHost().newTabSpec(tag).setIndicator(tab)
                .setContent(intent);
    }
}

thanks in advance..:Pragna


回答1:


If you want to switch to another tab from within a Tab, you can use this,

In your MainActivity which extends a tabActivity, specify a method like this,

  public void switchTabSpecial(int tab){
    tabHost.setCurrentTab(tab);
  }

Inside the onClick listener of your download button,

 mainAcitivity t=(mainActivity)this.getParent();
       t.switchTabSpecial(1);

Now this will traverse you from your first tab to second tab.



来源:https://stackoverflow.com/questions/6277249/android-tabwidget-need-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!