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
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With