Created
July 22, 2010 20:15
-
-
Save daithiocrualaoich/486524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait InMainThread { | |
private val handler = new Handler | |
def mainThread(block: => Unit) { | |
handler.post(new Runnable { | |
def run { block } | |
}) | |
} | |
} | |
class MyGUIView extends Activity with InMainThread { | |
private var view: TextView = _ | |
override def onCreate(savedInstanceState: Bundle) { | |
super.onCreate(savedInstanceState) | |
view = new TextView(this) | |
setContentView(view) | |
} | |
def methodCalledByBackgroundThread() { | |
// Can't invoke view.setText directly because not on the GUI thread, instead... | |
mainThread { view.setText("Background thread did this.") } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment