I think you might be misunderstanding the purpose of BaseAdapter
. BaseAdapter
-derived classes are meant to serve as an interface between a dataset and the AdapterView
in which you display that dataset's information (and/or interact with it.)
With that in mind, I kind of think the easiest way to accomplish what you're doing is going to be to keep track of whether or not the item is checked using a boolean
as part of the dataset. For example, if your dataset is an ArrayList<SomeObjectYouMadeUp>
, you'll want to add a boolean
member to SomeObjectYouMadeUp
; set it during the CheckBox
's OnCheckedChangeListener
, and use it to determine whether the CheckBox
should be visually checked during getView()
.
That might take some rethinking of your code, but trust me, you're probably going to want to do it. It's possible to do it the way you are describing, but it won't be easy or reliable; you'll want to get individual access to each visible view in your AdapterView
using the method described here, but again I have to recommend against this.
The biggest reason is that onSaveInstanceState
occurs most commonly during configuration changes - for example, a screen rotation. This means it is almost certainly an incorrect assumption that you'll be displaying the same Views. Say there are 10 Views visible in portrait orientation, and 5 visible in landscape. So the user rotates to landscape - which 5 do we get? Do you know for sure? You'll have to check each new View
against some identifying information you probably also had to keep in onSaveInstanceState
- and what if one of the new Views wasn't visible before the rotation?
The list of questions goes on. Do yourself a favor: save the check state with the rest of your dataset, and let Android figure it out for you.