Reputation: 8930
In a thread when I receive something from internet I want to notify the user and I do something like
new Thread(new Runnable(...
...
Log.d("tag", "going to redraw");
findViewById(R.id.view).setVisibility(View.VISIBLE);
findViewById(R.id.view).refreshDrawableState(); // tried this
findViewById(R.id.view).invalidate(); // and this together and separately
).start();
I always see the log, and sometimes see the view shown. I have no idea what's going on
I have tried to include the findViewById
in a runOnUIThread
but that didn't do the job either. Any tip on this ?
Upvotes: 1
Views: 2600
Reputation: 10977
Do not modify the UI in a Thread other than the UI Thread! Either use a Handler or Activity.runOnUiThread()
Upvotes: 4
Reputation: 44571
When you are not on the main Thread
you need to use postInvalidate()
on the View
instead of invalidate()
Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.
From the docs for invalidate()
This must be called from a UI thread.
Upvotes: 0