我有带有 3 个选项卡的 ActionBar。每个选项卡都有一个 Fragmemt。如何为每个选项卡分配一个活动(每个片段都有一个按钮,如何在该按钮上分配事件)?
public class TMABActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
Tab tab = actionBar
.newTab()
.setText("MyBooks")
.setTabListener(
new MyTabListener<NewsFragment>(this, "1",
NewsFragment.class, this));
actionBar.addTab(tab);
tab = actionBar
.newTab()
.setText("News")
.setTabListener(
new MyTabListener<MyBooksFragment>(this, "2",
MyBooksFragment.class, this));
actionBar.addTab(tab);
tab = actionBar
.newTab()
.setText("Account")
.setTabListener(
new MyTabListener<AccountFragment>(this, "3",
AccountFragment.class, this));
actionBar.addTab(tab);
}