我正在尝试使用Tab View应用程序。我正在使用getFragmentManager()方法来获取其他片段。但是当我运行应用程序时它停止工作。如果我给getSupportFragmentManager()然后它要求将simpleListFragment的类型更改为Fragment。请帮我。提前谢谢。
这是活动代码。
public class TapBar extends FragmentActivity implements ActionBar.TabListener{
private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabview);
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// For each of the sections in the app, add a tab to the action bar.
actionBar.addTab(actionBar.newTab().setText(R.string.title_section1).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.title_section2).setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.title_section3).setTabListener(this));
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar().getSelectedNavigationIndex());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
/**
* On first tab we will show our list
*/
if (tab.getPosition() == 0) {
MyFriendsListFragment simpleListFragment = new MyFriendsListFragment();
getFragmentManager().beginTransaction().replace(R.id.container, simpleListFragment).commit();
}
else if (tab.getPosition() == 1) {
AndroidList androidlidt = new AndroidList();
getFragmentManager().beginTransaction().replace(R.id.container, androidlidt).commit();
}
else {
AndroidVersionList androidversionlist = new AndroidVersionList();
getFragmentManager().beginTransaction().replace(R.id.container, androidversionlist).commit();
}
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
答案 0 :(得分:0)
import android.support.v4.app.ListFragment; 在你的MyFriendsListFragment,AndroidList,AndroidVersionList中 insted import android.app.ListFragment;