FragmentActivity onCreateView

帅比萌擦擦* 提交于 2020-01-16 04:17:12

问题


I try to use the Android compatibility library (or now called the support library) v4 for pre-honeycomb android devices. I understand that, instead of using the Fragment class, I should use the FragmentActivity class. According to all the tutorials I can find, I can use the onCreateView method as in the Fragment class:

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

However, the onCreateView method in the FragmentActivity seems to be different. The one I inherit from is:

public View onCreateView (String name, Context context, AttributeSet attrs)

This version is actually listed in the Android reference of the FragmentActivity class.
Seems all tutorials I can find do not state this difference, and all are calling the one in the Fragment class. Am I mistaking something here that I should be somehow able to call the onCreateView of the Fragment class version?


回答1:


I think this is wrong:

I understand that, instead of using the Fragment class, I should use the FragmentActivity class.

You should use FragmentActivity class insted of Activity class. In FragmentAcivity class it's enough that you override onCreate method.




回答2:


FragmentActivity and Activty are same. FragmentActivity is for Version (below 4)which are supports Fragment by using android.support.v4.jar . For Versions from 4 there is no FragmentActivity..u can check it out. FragmentActivity is for Calling showing Fragments..so u should not extends FragmentActivity when u develop fragment View. Fragments are part of the FragmentActivity.u can have more framgents. for ur doubt:check this http://developer.android.com/reference/android/app/Activity.html#onCreateView%28android.view.View,%20java.lang.String,%20android.content.Context,%20android.util.AttributeSet%29




回答3:


You've got it a little switched around. Fragment is still Fragment. Activity becomes FragmentActivity. Have a peek at the sample code that comes with the Android Compatibility Library. In particular, see FragmentLayoutSupport.java.




回答4:


Simple delete your gen folder...worked for me



来源:https://stackoverflow.com/questions/10498258/fragmentactivity-oncreateview

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