我是 Sherlock lib 的新手。我的代码如下
public class MainActivity extends SherlockFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
com.actionbarsherlock.app.ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.setTitle("PROFILE");
ActionBar.Tab frag1tab = actionbar.newTab().setText("LOGIN");
ActionBar.Tab frag2tab = actionbar.newTab().setText("REGISTER");
Fragment fragment1 = new Fragment_1();
Fragment fragment2 = new Fragment_2();
frag1tab.setTabListener(new MyTabListener(fragment1));
frag1tab.setTabListener(new MyTabListener(fragment2));
actionbar.addTab(frag1tab);
actionbar.addTab(frag2tab);
}
class MyTabListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabListener(Fragment fragment) {
this.fragment = fragment;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
ft.replace(R.id.fragment_container, fragment);
}
@Override
public void onTabSelected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
}
}
我也尝试过直接实现监听器,但没有运气。它显示错误如下
java.lang.RuntimeException: Unable to start activity java.lang.IllegalStateException:
Action Bar Tab must have a Callback