I have created a Thread in onCreate(). It is running fine. Now I want to change something in view, when the thread is over. But if add it in the run() method, it is giving android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. error. How to solve this problem?
Thread updateThread = new Thread() {
@Override
public void run() {
................
................
//this line is giving problem
loader.setVisibility(View.INVISIBLE);
}
};
updateThread.start();
You should use an AsyncTask http://developer.android.com/reference/android/os/AsyncTask.html instead of Thread, and do your loader.setVisibility(View.INVISIBLE) inside onPostExecute()