Skip to content Skip to sidebar Skip to footer

Use Observer In Fragment

I've a problem when using an observer in a fragment, I've implemented my own TextViewObserver, and I wan't to insert it in a Fragment: public class TextViewObserver extends TextVie

Solution 1:

In Android, you can only manipulate Views from the UI thread. You can run some code on the UI thread by using View.post(), like this:

@Overridepublicvoidupdate(java.util.Observable o, final Object arg) {
    this.post(newRunnable() {
        publicvoidrun() {
            this.setText(String.valueOf(arg));
        } 
    }
}

http://developer.android.com/reference/android/view/View.html#post(java.lang.Runnable)

Post a Comment for "Use Observer In Fragment"