Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh a view Android

Tags:

java

android

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?

like image 719
Sam97305421562 Avatar asked Jun 20 '09 07:06

Sam97305421562


2 Answers

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

like image 178
Prashast Avatar answered Sep 18 '22 11:09

Prashast


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.

like image 25
Josef Pfleger Avatar answered Sep 19 '22 11:09

Josef Pfleger