Search code examples
javaandroidlistadapter

How to update a listview within the custom adapter?


I have a custom adapter which extends ArrayAdapter, it includes checkboxes for each item in the list.

Within the getview itself I have the onCheckedChanged listener that deletes a item from the database if checked. However the listview does not update, and I cant call the notifyDataSetChanged() as I am not in the main class. Any ideas how?


Solution

  • Post the code so that readers can understand your problem.

    You dont have to set any listener in the class that is extending ArrayAdapter. In this class we only inflate the data to the views.

    Remove the onCheckedChanagedListener from Adapter class and place it in the ListActivity or Fragment that is using this Adapter.