Android: Default layout for listitem containing title and subtitle

12,869

Solution 1

Resource id is android.R.layout.simple_list_item_2

Upper text line has id android.R.id.text1 and lower one - android.R.id.text2

Layout is located in the <ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layout folder

OR

You can use TwoLineListItem from the default Android controls list(it is located under "Advanced" tab in Eclipse Layout Editor)

OR

You can build your own layout with anything you like(for example LinearLayout with orientation="vertical" and two TextEdits added

Solution 2

So The Best Way Is:- I took out the simple list item 2 and made an layout in my project and with little editing it took the same layout as you may give in android.R.simple_list_item_2

So the code is:-

   <?xml version="1.0" encoding="utf-8"?>

<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">

<TextView android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:textAppearance="?attr/textAppearanceListItem" />

<TextView android:id="@id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/text1"
    android:layout_alignStart="@+id/text1"
    android:layout_alignLeft="@+id/text1"
    android:textAppearance="?attr/textAppearanceListItemSmall" />

Share:
12,869
Xander
Author by

Xander

Updated on June 07, 2022

Comments

  • Xander
    Xander almost 2 years

    I have made a listitem, containing a title and a subtitle. Looking to the result, I think it doesn't look really professional. So that's why I'm asking.

    The listitem I'm looking for is pretty common (it's used in a lot of apps i.e. Android's default settings menu and it's also shown when you add a listview in the graphical layout editor tab in eclipse).

    So my question is: Where can I find a default layout for a listitem with a title and a subtitle?