2013-07-17 52 views
0

我有相同的代碼:刷新TabActivity上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(上目錄類的方法),如果我在菜單上的按鈕,點擊「刷新」 這種方法wiil刷新數據,並認爲這在TabActivity上。

+1

'TabActivity'已棄用了超過兩年。請考慮使用更現代的選項卡實施:操作欄選項卡,'FragmentTabHost',具有選項卡式指示符的'ViewPager'等。 – CommonsWare

+0

但是,如果我需要2.0版本的Android應用程序? – plsgogame

+0

只需使用Intent.FLAG_ACTIVITY_CLEAR_TOP。無論您在開始活動。你會在你面前刷新屏幕。 –

回答

1

正如在評論說,TabActivity已被廢棄,不應該使用。如果您需要支持舊設備,以ActionBarSherlock,這將做支持舊設備所有的髒活一起使用GrilledUI庫。