2013-03-07

Built-in Android ListView layouts: Part 2

See Part 1 here.
Android has several built-in ListView layouts that you can easily use without defining your own layout XML.

The source code needs cleanup and better documentation but it should give you an idea how to use the built-in layout.

android.R.layout.simple_list_item_activated_1
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
  android:background=
  "?android:attr/activatedBackgroundIndicator"
  android:minHeight=
  "?android:attr/listPreferredItemHeightSmall"
/>


android.R.layout.simple_list_item_activated_2
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:paddingTop="2dip"
  android:paddingBottom="2dip"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background=
  "?android:attr/activatedBackgroundIndicator"
  android:minHeight=
  "?android:attr/listPreferredItemHeight"
  android:mode="twoLine"
>

  <TextView android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart=
    "?android:attr/listPreferredItemPaddingStart"
    android:layout_marginTop="6dip"
    android:textAppearance=
    "?android:attr/textAppearanceListItem"
  />

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

</TwoLineListItem>


android.R.layout.simple_list_item_checked
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark="?android:attr/textCheckMark"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.simple_list_item_multiple_choice
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark=
  "?android:attr/listChoiceIndicatorMultiple"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.simple_list_item_single_choice
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark=
  "?android:attr/listChoiceIndicatorSingle"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.two_line_list_item
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">

  <TextView android:id="@android:id/text1"
  android:textSize="16sp"
  android:textStyle="bold"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  />

  <TextView android:id="@android:id/text2"
  android:textSize="16sp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  />

</LinearLayout>

3 comments:


  1. It's impossible not to appreciate waircut.net for providing such reliable content and valuable guidance. The excellent organization and practical resources make this platform both trustworthy and highly recommended.

    ReplyDelete
  2. I genuinely admire the quality here, rdpwrapper.org delivers informative content, excellent organization, and dependable resources that help users solve problems efficiently. This website deserves appreciation for its consistency, usefulness, and outstanding overall experience.

    ReplyDelete
  3. Every visit feels truly worthwhile because odinflashtool.org consistently shares valuable insights and dependable information. The website is easy to navigate, professionally designed, and filled with useful content that keeps visitors coming back again.

    ReplyDelete