Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a TwoLineListItem?

Tags:

android

I want to make a setings menu like this:

enter image description here

Is there a definitive guide on how to make TwoLineListItem's anywhere?

like image 802
nkcmr Avatar asked Aug 19 '11 19:08

nkcmr


3 Answers

You will need to use a custom listrow with a custom adapter.

Here is an example: http://geekswithblogs.net/bosuch/archive/2011/01/31/android---create-a-custom-multi-line-listview-bound-to-an.aspx

like image 111
MrZander Avatar answered Sep 30 '22 19:09

MrZander


In your case, extend PreferenceActivity and in the onCreate method:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);     
    addPreferencesFromResource(R.xml.preferences);      
    getPreferences();
}

Where you can inflate your view using a preferences.xml file - add a folder called xml to your res folder and add an xml file with stuff like:

<CheckBoxPreference
       android:title="@string/pref_sub_notify"
       android:defaultValue="true"
       android:summary="@string/pref_sub_notify_summary"
       android:key="subNotifyPref" />

  <ListPreference
       android:title="@string/pref_sub_expiry_warn"
       android:summary="@string/pref_sub_expiry_summary"           
       android:key="subExpiryDelayPref"
       android:defaultValue="7"
       android:entries="@array/sub_expiry_delay"
       android:entryValues="@array/sub_expiry_delay_values" />

In this case, the title is your first line and the summary is the second line.

like image 38
John J Smith Avatar answered Sep 30 '22 20:09

John J Smith


You need a custom View and a ListActivity. This tutorial may help. If you are working on a Settings Activity, why not extend PreferenceActivity?

like image 35
Phil Avatar answered Sep 30 '22 20:09

Phil