Skip to content

Instantly share code, notes, and snippets.

@felipehjcosta
Last active July 16, 2018 00:30
Show Gist options
  • Select an option

  • Save felipehjcosta/12f4f7952f901a04c8500f145fb35615 to your computer and use it in GitHub Desktop.

Select an option

Save felipehjcosta/12f4f7952f901a04c8500f145fb35615 to your computer and use it in GitHub Desktop.
RecyclerView DSL simple example
class MyActivity : Activity() {
private lateinit var recyclerView: RecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.my_activity)
recyclerView = findViewById<RecyclerView>(R.id.my_recycler_view).apply {
setHasFixedSize(true)
}
val items = listOf("Spider-Man", "Thor", "Iron Man", "Black Panther", "Hulk")
onRecyclerView(recyclerView) {
withLinearLayout {
orientation = LinearLayout.VERTICAL
reverseLayout = false
}
bind(R.layout.strings_list_item) {
withItems(items) {
on<TextView>(R.id.title) {
it.view?.text = it.item
}
}
}
}
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment