我尝试使用 google 教程在 android 中实现 3 个选项卡.....但我无法为每个选项卡创建不同的活动并浏览它们......
package com.example.tab;
import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Important-the following code in onCreate class adds tabs to action
// bar
final ActionBar actionBar = getActionBar();
// Specify that tabs should be displayed in the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
}
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction ft) {
// hide the given tab
}
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction ft) {
// probably ignore this event
}
};
// Now we add 3 Tabs specifying tab names and Tablistener
for (int i = 0; i < 3; i++) {
if (i == 0) {
actionBar.addTab(actionBar.newTab().setText("Tech")
.setTabListener(tabListener));
}
if (i == 1) {
actionBar.addTab(actionBar.newTab().setText("Politics")
.setTabListener(tabListener));
}
if (i == 2) {
actionBar.addTab(actionBar.newTab().setText("Sports")
.setTabListener(tabListener));
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) { // Method to add action bar
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar, menu);
return super.onCreateOptionsMenu(menu);
}
}
在此之后我应该尝试什么并为每个选项卡创建 3 个活动?