简体   繁体   中英

How to display a listpreference as a regular activity?

I have in my activity settings a lispreference that is shown by the default style which is similar to a dialog view.

Instead, I want it to be shown like a regular listview within an activity: (like this image: http://cdn4.staztic.com/cdn/screenshot/meteogram-weather-847838-0.jpg )

I am thinking of two ways for accomplishing that:

  1. Extends Preference and call the setIntent() method of the extended Preference then start an activity that contains the listview and store the selected choice in SharedPrefs.

  2. Customize the appearence of the ListPreference and make it appear like a regular activity but I didn't find how this can be done

Any thoughts on this would be appreciated

--

Amine

I had a lot off trouble with this and i finally gave up. By extending the holo.light theme with my own theme i could change it(eg. checkbox marks were orange) but i couldn't get the listpreference to change color.you can find in this themes.xml how it should be done

themes.xml

Finally I did it using the following XML (R.xml.prefs_location):

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <Preference
        android:key="someKey"
        android:summary="Some text"
        android:title="Location" 
        />        
</PreferenceScreen>

And in a PreferenceFragment class I've set up an intent to open the desired activity when the preference is clicked:

Public class FragLocationPref extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.prefs_location);
        Intent i = new Intent(this.getActivity().getBaseContext(), LocationChooseActivity.class);
        findPreference("someKey").setIntent(i);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM