Search code examples
javaandroidandroid-widgetandroid-arrayadapter

Update data in Arrayadapter


i have this problem, i have

private ArrayList<CustomItem> items; 
private ArrayAdapter<CustomItem> arrayAdapter;

i show the data present in items, this data i see in listview, now i want to update data and see this new data

if (!items.isEmpty()) {
    items.clear(); // i clear all data
    arrayAdapter.notifyDataSetChanged(); // first change
    items = getNewData();// insert new data and work well
    arrayAdapter.notifyDataSetChanged();  // second change                                      
}

in the first change i see the data are cleaned, but in second change i don't see the new data in listview, i check and the item don't empty

i don't know where is the error, can you help me? best regads Antonio


Solution

  • Assuming the getNewData() function returns ArrayList<CustomItem>, can you change the line:

    items=getNewData();
    

    to

    items.addAll(getNewData());
    

    and see if that works?