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>
|
in simple list item single choice, my radio buttons do not get selected. i have used this list layout but my options do not get checked on selection
ReplyDelete