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