1

当我提到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”无济于事。有人可以指出解决方案吗?

4

1 回答 1

3

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

FragmentTransaction ft = openFragmentTransaction();

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
于 2013-04-26T10:24:56.060 回答