Search code examples
androidradio-buttonsharedpreferencespreferencelistpreference

Radio button list on Android


I want to have a list with radio buttons displayed when a Preference in a PreferenceActivity is selected(like when the Music preference is selected on an HTC sensation in the default gallery app-slideshow). I do not want to use fragments because the above model was running Gingerbread and doesn't support fragments. The list should also have buttons at the bottom. It's a sort of ListPreference. But, like a customized ListPreference(so that it has more than the default single button and also the list occupies the entire screen) So, how do you display a list like this?


Solution

  • Use this as the TextView for the list items:

    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/radio_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical" 
        android:paddingLeft="3dip"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:paddingRight="3dip"
        android:padding="10dip"    
        android:singleLine="true"
        android:ellipsize="marquee" />