I've got a ListView
, each of item
of which contains a ToggleButton
. After I toggle it and then scroll up or down, the ListView is recycling the Views and so some of the others are mirroring the checked state of the ToggleButton
. I don't want this. How can I prevent it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
May be you should try creating your own list view with scroll view and a container that holds the children that are added to the container programatically. set the tag for identifying the child or you could use the order of the child for that
You could use a
HashMap
to save your buttons state:and after inflating the view you read the
HashMap
to see if it was checked or not:Not sure if it helps in your way. I had also problems with recycling my
EditText
in myListView
.Android recycles list items for performance purposes. It is highly recommended to reuse them if you want your ListView to scroll smoothly.
For each list item the
getView
function of your adapter is called. There, is where you have to assign the values for the item the ListView is asking for.Have a look at this example:
Notice that
ViewHolder
is a static class we use to recycle that view. Its properties are the views your list item has. It is declared in your adapter.mToggles
is declared as a private property in your adapter and set with a public method like this:Have a look at other custom ListView examples for more information.
Hope it helps.
Add this two methods to your Adapter.