问题
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