0

I'm trying to implement this example from this MultiChoiceAdapter library.

It looks perfect so far. The only thing that I changed is the ListView height and added a Button after such ListView.

enter image description here

Now, my idea with that Button is to update the adapter. For that, I created the following method:

private void updateData(Bundle savedInstanceState){
    List<String> items = Arrays.asList("Item1", "Item2", "Item3", "Item4");
    adapter = null;
    adapter = new ComplexItemLayoutAdapter(savedInstanceState, items);
    adapter.notifyDataSetChanged();
}

At the end, it did not work. I tried following this answer, but it did not work because this example does not extend ArrayAdapter.

What can I do to update this kind of adapter?

Many thanks.

Community
  • 1
  • 1
Luis Lavieri
  • 3,689
  • 5
  • 32
  • 60

1 Answers1

1

Created one method in ComplexItemLayoutAdapter named setData(List<String> items) and set these items to existing data.

And change your method implementation

    private void updateData(Bundle savedInstanceState){
        List<String> items = Arrays.asList("Item1", "Item2", "Item3", "Item4");
        adapter = null;
        adapter = new ComplexItemLayoutAdapter(savedInstanceState, items);
        adapter.notifyDataSetChanged();
    }

to

    private void updateData(){
        List<String> items = Arrays.asList("Item1", "Item2", "Item3", "Item4");
        adapter.setData(items);
        listView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
ravindra.kamble
  • 1,023
  • 3
  • 11
  • 20
  • I feel stupid. I noticed that I was using a different `adapter` than `ComplexItemLayoutAdapter` in the example. How dumb that I did not see it before. Thanks! – Luis Lavieri Jan 14 '14 at 04:35