java getSupportFragmentManager() 方法未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17145402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getSupportFragmentManager() method is undefined
提问by user1910290
I have a Main activity which extends SherlockActivity
我有一个扩展的主要活动 SherlockActivity
The following code seems to be giving me trouble
以下代码似乎给我带来了麻烦
PopularFragment fragment = new PopularFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
I get the error "Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager
"
我收到错误“ Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager
”
I tried getSupportFragmentManager() but that gives me this error "The method getSupportFragmentManager() is undefined for the type Main.DrawerItemClickListener
"
我试过 getSupportFragmentManager() 但这给了我这个错误“ The method getSupportFragmentManager() is undefined for the type Main.DrawerItemClickListener
”
I am playing with the new android navigation drawer, in my libs/ folder I only have support library v13
我正在玩新的 android 导航抽屉,在我的 libs/ 文件夹中我只有 support library v13
my fragments imports are import android.support.v4.app.Fragment;
我的片段导入是 import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
How do I solve this issue? Thanks!
我该如何解决这个问题?谢谢!
回答by Lingviston
You should extend SherlockFragmentActivity
not SherlockActivity
. And call getSupportFragmentManager
instead of getFragmentManager
.
你应该继承SherlockFragmentActivity
不是SherlockActivity
。并调用getSupportFragmentManager
而不是getFragmentManager
.
回答by Felipez
I don't know if it is a good practice, But I have changed with newFragment.show(this.getFragmentManager(), "datePicker");
And the datePicker is working.
我不知道这是否是一个好习惯,但我已经改变了newFragment.show(this.getFragmentManager(), "datePicker");
并且 datePicker 正在工作。
回答by Nik
Try:
尝试:
YourActivityClassName.this.getSupportFragmentManager();