A common thing you might want to do, when you developing an Android app, is to have a ListView of checkable items. For instance, you might want to have a functionality in your app to share something with a bunch of people, who you would like to select from a list of contacts. For common choice for this task is to use a CheckedTextView and the android:choiceMode parameter of the ListView. This extension of a regular TextView has a check box on the right, so that it can be selected. However, there is a limitation here. CheckedTextView has to be the root element of the layout that you use for your items. So if you wish to display multiple things (user name and email) for each item by using a LinearLayout, you are out of luck. The reason for this limitation is that he root item must implement the Checkable interface and the LinearLayout doesn’t implement it. The solution here is to override LinearLayout to implement the required interface. I present to you CheckableLinearLayout. Upon inflation it searches through its children for the CheckedTextView, and then forwards any calls required by the Checkable interfaces to that component:
Now, we can use that component in the layout file for our list items:
Make sure you set in your ListView's XML: android:choiceMode=”multipleChoice”.
Follow me @tokudu