Question

I have my custom ConfigActivity which extends PreferenceActivity (from android.preference.PreferenceActivity). The layout for this activity contains a <ListView android:id="@android:id/list".... Inside this layout, I need to programmatically add/replace a couple of other Fragments I have created that extend android.support.v4.app.Fragment.

However, Eclipse says:

The method getSupportFragmentManager() is undefined for the type ConfigActivity.

I tried replacing it for just getFragmentManager(), but the following call:

ft.add(R.id.fHeader, new MyCustomFragment());

results in the following error:

The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyCustomFragment)

Is my only option to NOT use my custom Fragments that extends the support library's Fragment class inside ConfigActivity?

Was it helpful?

Solution

I think you will need to make your activity extend FragmentActivity or some subclass of FragmentActivity to work with Fragments if you are using android.support.v4.app.Fragment. Other option can be to make your minimum sdk version set to 12 and check your code without using support libraries.

OTHER TIPS

Usual Activity do not have FragmentManager. If you want to use Fragment in your Activity, you should use FragmentActivity which is in support libs.
Because android is open source, you can use the code in PreferenceActivity, and make a MyPreferenceActivity extends FragmentActivity. Hope it will be helpful :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top