Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preference Activity Vs PreferenceFragment?

In preference Activity we can use these two methods SetContentView(R.layout.main) and addXmlFromResources(R.xml.Preferences) for customizing the preference screen. For example see this Adding a button on Prefernce Screen

Is this possible in PreferenceFragment?

In PreferenceFragment, I have added addPreferencesFromResource(R.xml.PreferenceScreen); in onCreate method. When I use onCreateView it's getting force closes. I have tried Layout Inflator also. It's not working.

So is this possible only on preference Activity? not Preference Fragment?

P.S- I am using support V 13 Library. So I have created Preference Fragment in Fragment Pager Adapter. Please don't suggest to me to create Preference Activity for preference Fragment

like image 298
Asthme Avatar asked Oct 01 '22 20:10

Asthme


1 Answers

You can use

addPreferencesFromResource(int res);

in both PreferenceFragment and PreferenceActivity, inside the onCreate() method. Bear in mind that PreferenceFragment should be used in post Honeycomb Android Versions as a replacement for PreferenceActivity.

If you want a custom-layout for your PreferenceActivity, you can call setContentView() in the onBuildHeaders() method, but not in the onCreate().

like image 147
Philipp Jahoda Avatar answered Oct 19 '22 17:10

Philipp Jahoda