Search code examples
androidlistviewandroid-arrayadapter

ListView ArrayAdapter reverse of notifyDataSetChanged


notifyDataSetChanged updates the view/adapter when you change the object. But how to have the object updated when the view is changed by the user (Checkbox checked)

I am trying to put the Checkbox onclick listener in the newView(...) and my adapter is in separate file. My worry is that if I update the array object only internally then when the notifidatasetchanged is called the update will be lost. Is it true? Can I update the main object found in the Activity from the newView() found in the adapter in different file?


Solution

  • When the CheckBox is checked/unchecked, the onClick method for that CheckBox will be called. When that happens, you can change the object in the backing data for your adapter depending on whether the CheckBox is checked or not.

    Please, go over the official tutorial: http://developer.android.com/guide/topics/ui/controls/checkbox.html