我有相同的代码:
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() 这样的类别类上创建方法,如果我点击菜单“刷新”上的按钮,此方法将刷新数据并在 TabActivity 上查看。