1

I am trying to refresh a GalleryView with new items by adding the items to the Adapter and doing the following inside the handler which is called from inside doInBackground method of AsyncTask.

private final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        if(msg.arg1 == 1){

            gaAdapter.notifyDataSetChanged();
            ga.setAdapter(gaAdapter);
            ga.setSelection(midposition);
        }
    }   
};

The GalleryView seems to respond to the above code but does not automatically refresh itself. The items are updated only when it is horizontally scrolled. How can I do this automatically?

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Abhishek Sharma
  • 609
  • 1
  • 11
  • 22

2 Answers2

1

notifyDataChanged() need to be involved on UI thread, try this:

runOnUiThread(new Runnable() {
  public void run() {
    gaAdapter.add(newListItem);
    gaAdapter.notifyDataSetChanged();
    ga.setSelection(midposition);
  }
});
yorkw
  • 40,926
  • 10
  • 117
  • 130
  • I am going to accept your answer as it is one of the ways of doing it. However, I used Handlers to get the job done. I was just not doing it right the first time. – Abhishek Sharma Nov 18 '11 at 06:21
0

Try using
ga.invalidate()

Rajdeep Dua
  • 11,190
  • 2
  • 32
  • 22