Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use getSupportFragmentManager() Inside PreferenceActivity

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?

like image 375
Dzhuneyt Avatar asked Nov 02 '22 12:11

Dzhuneyt


1 Answers

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.

like image 112
Red Devil Avatar answered Nov 15 '22 03:11

Red Devil