对于new ActionBar.OnNavigationListener(){}类型,未定义openFragmentTransaction()方法

时间:2013-04-26 09:30:19

标签: android android-actionbar spinner android-arrayadapter

当我引用Android Developers链接来制作下拉列表时,我在Eclipse中遇到错误:

The method openFragmentTransaction() is undefined for the type new ActionBar.OnNavigationListener(){}

这是网站给出的示例代码段(迄今为止):

mOnNavigationListener = new OnNavigationListener() {
  String[] strings = getResources().getStringArray(R.array.action_list);

  @Override
  public boolean onNavigationItemSelected(int position, long itemId) {

    ListContentFragment newFragment = new ListContentFragment();
    FragmentTransaction ft = openFragmentTransaction(); //<--ERROR HERE

    ft.replace(R.id.fragment_container, newFragment, strings[position]);
    // Apply changes
    ft.commit();
    return true;
  }
};

问题是,我不知道这种方法来自哪里?我的主要活动类是SherlockFragmentActivity,我从android.support.v4.app.FragmentTransaction导入。按“ctrl + shift + o”将无济于事。有人可以给出解决方案的指针吗?

1 个答案:

答案 0 :(得分:3)

我想我找到了答案。只需改变

FragmentTransaction ft = openFragmentTransaction();

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();