I have a ListActivity with an array adapter declared like arrayAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_checked);
This shows a bunch of rows with checkmarks on the far right. Can you tell me how to get a reference to those checkmarks or how to check/uncheck them?
相关问题
- 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
I had a similar problem and tried the solutions provided here but I still had a lot of problems. I just wanted to have a list with selectable "test cases" and two buttons "select all tests" and "run selected tests" (therefore I didn't want to have just a ListActivity). As mentioned by "JDC" getChildAt (and getChildCount) refer to the currently displayed items but my list didn't fit on the screen and therefore I couldn't use it to select all list items. Additionally if I used setChecked of the CheckedTextView I had the problem that the selection disappeared as soon as I scrolled the list. My solution is the code below that fixes these issues by using getCount and setItemChecked of the ListView (see also the comments in the source code). Additionally it shows how to retrieve the checked items.
Here is also the appropriate layout (main.xml):
The CheckedTextView itself handles the checkbox. It is passed in as the second argument (View v) in the onListItemClick handler. So, you can simplify your code as follows:
The closest I can do is change the checkmark after a cell is clicked using:
I would still like to be able to set the checkmarks without the user touching any cells.