8

I want to refresh a listview. When I am getting a value from different class I want it to update that to list view. I am creating a thread for refreshing the list but I am getting an exception:

Only the original thread that created a thread a view hierarchy can touch its views

How to proceed?

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
Sam97305421562
  • 3,027
  • 10
  • 35
  • 45

2 Answers2

17

Instead of trying to refresh the view to update the list just take the Adapter object and call the notifyDataSetChanged() API.

Prashast
  • 5,645
  • 3
  • 30
  • 31
3

Whenever you work with multiple threads in an Android GUI you should use Handlers. The Android Dev Guide has a good example of how to use Handlers with a ProgressDialog when you expand the subsection Example ProgressDialog with a second thread here.

The example should be easy to understand and help you to apply the same concept to your list view.

Josef Pfleger
  • 74,165
  • 16
  • 97
  • 99
  • Also, see this similar question : http://stackoverflow.com/questions/3280141/android-calledfromwrongthreadexception-only-the-original-thread-that-created – Vincent Cantin Mar 20 '12 at 07:59