Reputation: 9429
I m coding some ui screens on android. sometime I need to see ui changes immediately, but that changes can be seen on next ui thread request. so, for example if I remove a view on screen and add another view programmatically, then change whole view (with viewAnimator), removing view can be observed, but new view can not be observed. I m sure new view is added, because when I go back to first page, new view is on screen.
which function should I call add or remove some view on screen to see its effect immediatlety ?
I tried invalidate(), but it doesnt work for my case
Upvotes: 7
Views: 1742
Reputation: 36289
The best way to ensure that a change will be made to a view as soon as the view is ready is to add a Runnable
to the view's message queue:
view.post(new Runnable(){
@Override
public void run() {
//TODO your code
}
});
Upvotes: 2
Reputation: 4399
It sounds like, if you say the UI only updates on the next UI thread request, that you are modifying UI elements from another thread. Therefore, you must modify them in a Runnable using runOnUiThread. So, for example:
//example code
//where you are trying to modify UI components, do this instead
runOnUiThread(new Runnable(){
public void run(){
//update UI elements
}
});
Upvotes: 6
Reputation: 9300
invalidate() on views that have no drawable (even transparen) or no children is not called. You have to at setBackgroundDrawable(Color.Transparent) to all of them or add a dummy child view at development to observe changes.
Also notice that at Android 3 + the rendering system has changed. When you invalidate parent the children are not always invalidated. You should invalidate the whole tree manually if you want the same beahvior as lower versions
Upvotes: -2