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