Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Created November 15, 2016 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sembozdemir/631b08c5746221990a17afb81829e69e to your computer and use it in GitHub Desktop.
Save sembozdemir/631b08c5746221990a17afb81829e69e to your computer and use it in GitHub Desktop.
ToDoKotlin - MainActivity.kt (with Anko DSL)
class MainActivity : AppCompatActivity() {
val todoListAdapter = TodoListAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
verticalLayout {
recyclerView {
val orientation = LinearLayoutManager.VERTICAL
layoutManager = LinearLayoutManager(ctx, orientation, false)
addItemDecoration(DividerItemDecoration(ctx, LinearLayout.VERTICAL))
adapter = todoListAdapter
}.lparams(width = matchParent,
height = dip(0),
weight = 1f)
val editText = editText {
hint = "Add note..."
}
button {
text = "Add"
onClick {
val note = editText.asString()
todoListAdapter.add(note)
editText.clear()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment