Android: Default layout for listitem containing title and subtitle
Asked Answered
A

2

16

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?

Albinaalbinism answered 13/3, 2013 at 16:12 Comment(0)
V
25

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

Vibrant answered 13/3, 2013 at 16:14 Comment(1)
m1shk4 has right, or you can easy make your own custom row ! In 10-20 XML lines it's done !Benzedrine
E
1

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" />

Envelope answered 14/3, 2016 at 4:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.