The problem is setAdapter
will clear all the previous items. So you need to avoid setAdapter
when you add new items.
Instead you need to add the new item into the existing adapter.
If your custom adapter is ArrayAdapter
, You can simply add like this
imageAdapter.add(yourObject); // imageAdapter is the instance you created first time when you setAdapter.
add()
method with call notifyDataSetChanged
to notify the `GridView' to refresh the UI.
If your custom adapter is BaseAdapter
, then have a add() method in the Custom Adapter class
and call it to add new items.
public void add(String[] newImages){
// add the items to the previous array
this.mobileValues.addAll(Arrays.asList(newItems));
// notify the data changed
notifyDataSetChanged();
}
Hope it helps you.