簡體   English   中英

在TabHost上刷新TabActivity

[英]Refresh TabActivity on TabHost

我有相同的代碼:

public class MainActivity extends TabActivity  {
private TabHost mTabHost;

private void setupTabHost() {
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
    // create tabs and etc...
    setupTabHost();
    mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    setupTab(new TextView(this), "Category", "Category.class");
    setupTab(new TextView(this), "Top", "Top.class");
    setupTab(new TextView(this), "Favorite", "Favorite.class");

}

    private void setupTab(final View view, final String tag, final String className) {
    View tabview = createTabView(mTabHost.getContext(), tag);
        TabHost tabHost = getTabHost();    
        TabHost.TabSpec spec;   
            Intent intent;
        intent = new Intent().setClass(this, Category.class);
            if (className.equals("Category.class")) {
            intent = new Intent().setClass(this, Category.class);}
            if (className.equals("Top.class")) {
                intent = new Intent().setClass(this, Top.class);}
            if (className.equals("Favorite.class")) {
            intent = new Intent().setClass(this, Favorite.class);}


            TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent); {
            };
            mTabHost.addTab(setContent);
}


    private static View createTabView(final Context context, final String text) {
    View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text);
    return view;
}

我想在Refres()之類的Category類上創建方法,如果我點擊菜單“ Refresh”上的按鈕,則此方法將刷新數據並在TabActivity上查看。

正如評論中所說,TabActivity已過時,不應使用。 如果需要支持較舊的設備,請結合使用GrilledUI庫和ActionBarSherlock ,它將完成支持較舊設備的所有骯臟工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM