Skip to content

Instantly share code, notes, and snippets.

@haroldl
Last active January 4, 2016 03:19
Show Gist options
  • Save haroldl/8560731 to your computer and use it in GitHub Desktop.
Save haroldl/8560731 to your computer and use it in GitHub Desktop.
val t = findViewById(R.id.textView1).asInstanceOf[TextView]
val b = findViewById(R.id.button1).asInstanceOf[Button]
b setOnClickListener {
view: View =>
backgroundThread {
// Do things like network requests here in the background thread...
Thread.sleep(3000)
uiThread {
// Back on the main thread, update the UI...
t.setText("Done with async.")
}
// More background work...
uiThread {
// More main thread UI changes...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment