For this type of list let's go with an extension of the ArrayAdapter. ![]() A simple way is to do this is to define an array of items in strings.xml:Īfter the layouts are set we would need a flavour of the Adapter class so we can fill the list with data. Let's define some static values for the list elements. From top to bottom, I'm try to display: a TextView (header) a ListView with an index strip to the right of it (I use hori. This is mandatory, otherwise the ToggleButton will consume the click notifications. I checked out a similar question to this but it didn't solve my problem. What is to note here is the attribute android:focusable="false" for the ToggleButton. The code was tested on Android Studio and is intended for SDK 4.4+ (because everything that is below 4.4 should disappear, in my opinion).Īfter creating a new project with a blank activity, the first step is to modify the layout for the main activity, as follows:Īfter that we need a new layout for the list row, let's call it row_layout.xml: ![]() So this is my way of implementing a list where each row consists of a TextView and a ToggleButton. ![]() There are lots of tutorials out there on creating lists with multiple elements, but none seem to work out of the box, with listeners and all.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |