Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apply ui changes immediately

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

like image 564
Adem Avatar asked Sep 16 '12 11:09

Adem


People also ask

How do I run the Ui policy again?

The only way to run it again is to delete the content of one of the fields, then click outside the box (I assume this sets the condition to false) then I can add new text to the field and the UI Policy finally runs again.

How can I update the UI of a thread?

Using a worker thread is probably the best way, but if you want another option you can take a look here - seems that you can update the UI using the Dispatcher .PushFrame () API. Unfortunetly nobody seems to know how safe is this method. Another idea is to use the OnIdle () function and do one iteration per call.

When are changes applied immediately or asynchronously?

If you choose to apply the change immediately, it occurs immediately. If you don't choose to apply the change immediately, and you change the setting from a nonzero value to another nonzero value, the change is applied asynchronously, as soon as possible. Otherwise, the change occurs during the next maintenance window.

How do I apply changes to a DB instance immediately?

When you modify a DB instance, you can apply the changes immediately. To apply changes immediately, you choose the Apply Immediately option in the AWS Management Console. Or you use the --apply-immediately parameter when calling the AWS CLI or set the ApplyImmediately parameter to true when using the Amazon RDS API.


2 Answers

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
    }
});
like image 117
dennisdrew Avatar answered Oct 14 '22 15:10

dennisdrew


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
    }
});
like image 36
Phil Avatar answered Oct 14 '22 16:10

Phil