README.md
1
2Android CustomChoiceList Sample
3===================================
4
5This sample demonstrates how to create custom checkable layouts, for use with ListView's choiceMode
6attribute.
7
8Introduction
9------------
10
11This sample demonstrates how to create custom single- or multi-choice [ListView][1] UIs on Android.
12
13When a ListView has a `android:choiceMode` attribute set, it will allow users to "choose" one or more items. For
14exmaple, refer to `res/layout/sample_main.xml` in this project:
15
16```xml
17<ListView android:id="@android:id/list"
18 android:layout_width="match_parent"
19 android:layout_height="0dp"
20 android:layout_weight="1"
21 android:paddingLeft="@dimen/page_margin"
22 android:paddingRight="@dimen/page_margin"
23 android:scrollbarStyle="outsideOverlay"
24 android:choiceMode="multipleChoice" />
25```
26
27The framework provides these default list item layouts that show standard radio buttons or check boxes next to a single
28line of text:
29
30- android.R.layout.simple_list_item_single_choice
31- android.R.layout.simple_list_item_multiple_choice.
32
33In some cases, you may want to customize this layout. When doing so, the root view must implement the Checkable
34interface. For an example, see this sample's `CheckableLinearLayout` class.
35
36Lastly, remember to use padding on your ListViews to adhere to the standard metrics described in the Android Design
37guidelines. When doing so, you should set the `android:scrollbarStyle` attribute such that the scrollbar doesn't inset.
38
39[1]: http://developer.android.com/reference/android/widget/ListView.html
40
41Pre-requisites
42--------------
43
44- Android SDK 28
45- Android Build Tools v28.0.3
46- Android Support Repository
47
48Screenshots
49-------------
50
51<img src="screenshots/1-main.png" height="400" alt="Screenshot"/> <img src="screenshots/2-settings.png" height="400" alt="Screenshot"/>
52
53Getting Started
54---------------
55
56This sample uses the Gradle build system. To build this project, use the
57"gradlew build" command or use "Import Project" in Android Studio.
58
59Support
60-------
61
62- Google+ Community: https://plus.google.com/communities/105153134372062985968
63- Stack Overflow: http://stackoverflow.com/questions/tagged/android
64
65If you've found an error in this sample, please file an issue:
66https://github.com/googlesamples/android-CustomChoiceList
67
68Patches are encouraged, and may be submitted by forking this project and
69submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
70
71License
72-------
73
74Copyright 2019 The Android Open Source Project, Inc.
75
76Licensed to the Apache Software Foundation (ASF) under one or more contributor
77license agreements. See the NOTICE file distributed with this work for
78additional information regarding copyright ownership. The ASF licenses this
79file to you under the Apache License, Version 2.0 (the "License"); you may not
80use this file except in compliance with the License. You may obtain a copy of
81the License at
82
83http://www.apache.org/licenses/LICENSE-2.0
84
85Unless required by applicable law or agreed to in writing, software
86distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
87WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
88License for the specific language governing permissions and limitations under
89the License.
90