Reputation: 11000
I want to make a setings menu like this:
Is there a definitive guide on how to make TwoLineListItem
's anywhere?
Upvotes: 6
Views: 3902
Reputation: 6439
I had a similar problem, but my desired list's item should have an image followed by two strings, one above the other (just as you want). I found the solution here. It worked easily for me and I think it will work well for you too (you just need to remove the ImageView
part appropriately).
Upvotes: 0
Reputation: 11923
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.
Upvotes: 2
Reputation: 3090
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
Upvotes: 3
Reputation: 42849
There is a pretty good tutorial here on how to create custom list items. The basic idea is that you define the layout of the list item just as you define the layout for an Activity
. You then subclass ArrayAdapter
(or BaseAdapter
), and override the getView(...)
method to return your custom list item View
.
Upvotes: 0
Reputation: 36289
You need a custom View
and a ListActivity. This tutorial may help. If you are working on a Settings Activity, why not extend PreferenceActivity?
Upvotes: 1