Search code examples
androidlistadapter

Calling notifyDataSetChanged on a ListAdapter


I have a ListAdapter as shown below:

setListAdapter(new ArrayAdapter<String>(DeleteMenu.this,             
                                  android.R.layout.simple_list_item_1, 
                                  classes));

I am trying to call notifyDataSetChanged() on it within an onListItemClick() function. I've tried a few different ways and looked at similar questions here on StackOverFlow but I still can't figure it out.

Can someone please help?

Edit: I should be more clear, I'm not getting an error, I simply don't know what to call the function notifyDataSetChanged() method on. Do I have to assign my ListAdapter to a variable and call it like var.notifyDataSetChanged()?


Solution

  • You should call notifyDataSetChanged on Adapter.

    Adapter adapter = new Adapter();
    ListView list = (ListView) findViewById(R.id.listview);
    list.setAdapter(adapter);
    adapter.notifyDataSetChanged();