getFragmentManager vs getSupportFragmentManager ERROR

左心房为你撑大大i 提交于 2020-06-27 06:35:11

问题


i need help for this . I realize sth very strange about this. In order to disable the Action bar (Title) , i need to add in this code

requestWindowFeature(Window.FEATURE_NO_TITLE);

So this only works I change from

extends AppCompatActivity

To this

extends Activity

So after changing that, I got error for the getFragmentManager.

Please have a look at the screenshot. And let me know if u guys have any idea wads going on? THx


回答1:


Use getSupportFragmentManager() instead of getFragmentManager(). AppCompatActivity is v4 library therefore required to use v4 functions

And to use it in Activity instead of Activity change it to FragmentActivity. Then you can use getSupportFragmentManager()




回答2:


requestWindowFeature() is not supported in AppCompatActivity thats why you could not use that method with AppCompatActivity.

Also if you are using AppCompatActivity you need to use SupportFragment and if you use Activity then use Fragment.




回答3:


If you are using this import import android.support.v4.app.Fragment;,

then you must use getSupportFragmentManager.

Hope this helps.




回答4:


You have to use the Compat method getSupportFragmentManager() instead of the regular one.

That's because it returns an object of type android.app.FragmentManager which is the type of the object where you're trying to store it.

If you use the regular method getFragmentManager() it'll return an object of type android.app.FragmentManager, which is an incompatible type.



来源:https://stackoverflow.com/questions/38453111/getfragmentmanager-vs-getsupportfragmentmanager-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!