简体   繁体   中英

android tabwidget need help

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM