to top
CustomChoiceList / res / layout /

list_item.xml

1
<!--
2
  Copyright 2013 The Android Open Source Project
3
 
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
  you may not use this file except in compliance with the License.
6
  You may obtain a copy of the License at
7
 
8
      http://www.apache.org/licenses/LICENSE-2.0
9
 
10
  Unless required by applicable law or agreed to in writing, software
11
  distributed under the License is distributed on an "AS IS" BASIS,
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
  See the License for the specific language governing permissions and
14
  limitations under the License.
15
  -->
16
 
17
<!--
18
    The ListView from sample_main.xml has a choiceMode set, meaning that when a user
19
    selects a list item, the ListView will set the state for that item's root view
20
    (this CheckableLinearLayout) to "checked". Note that this requires that the root view
21
    implements the Checkable interface. Once the root view is checked, any children that
22
    have the duplicateParentState attribute set will inherit this "checked" state.
23
-->
24
<com.example.android.customchoicelist.CheckableLinearLayout
25
    xmlns:android="http://schemas.android.com/apk/res/android"
26
    android:orientation="horizontal"
27
    android:layout_width="match_parent"
28
    android:layout_height="match_parent"
29
    android:paddingLeft="8dp"
30
    android:paddingRight="8dp"
31
    android:minHeight="?android:listPreferredItemHeight"
32
    android:gravity="center_vertical">
33
 
34
    <!--
35
        The duplicateParentState attribute on this TextView, along with the color state list
36
        used in the textColor attribute causes its text color to change when its parent
37
        is checked or unchecked.
38
    -->
39
    <TextView android:id="@android:id/text1"
40
        android:duplicateParentState="true"
41
        android:layout_width="0dp"
42
        android:layout_weight="1"
43
        android:layout_height="wrap_content"
44
        android:textAppearance="?android:textAppearanceMedium"
45
        android:textColor="@color/hideable_text_color" />
46
 
47
    <!--
48
        The duplicateParentState attribute on this ImageView, along with the state list
49
        drawable in the src attribute causes its image to change when its parent
50
        is checked or unchecked.
51
 
52
        To use the standard radio or checkmark image, set the src to
53
        ?android:listChoiceIndicatorMultiple or ?android:listChoiceIndicatorSingle. These
54
        are system theme attributes that reference a state list drawable.
55
    -->
56
    <ImageView android:src="@drawable/ic_hideable_item"
57
        android:duplicateParentState="true"
58
        android:layout_width="wrap_content"
59
        android:layout_height="wrap_content"
60
        android:layout_marginLeft="16dp" />
61
 
62
</com.example.android.customchoicelist.CheckableLinearLayout>