Skip to content

Instantly share code, notes, and snippets.

@whalemare
Created September 29, 2017 12:59
Show Gist options
  • Save whalemare/e5cb7a1af76e15e45a0e36964e9a3f6a to your computer and use it in GitHub Desktop.
Save whalemare/e5cb7a1af76e15e45a0e36964e9a3f6a to your computer and use it in GitHub Desktop.
package com.mscharhag.groovytodo.activities
import android.app.Activity
import com.mscharhag.groovytodo.R
import com.mscharhag.groovytodo.ToDo
class MainActivity extends Activity {
@Override
protected void onStart() {
super.onStart()
setContentView(R.layout.create_todo)
def button = findViewById(R.id.newTodoButton)
// use groovy multiple assignment to map view ids to variables
def (title, description) = [R.id.newTitle, R.id.newDescription].collect(this.&findViewById)
button.onClickListener = {
application.toDos << new ToDo(title.text.toString(), description.text.toString())
finish()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment