Last active
July 16, 2018 00:30
-
-
Save felipehjcosta/12f4f7952f901a04c8500f145fb35615 to your computer and use it in GitHub Desktop.
RecyclerView DSL simple example
This file contains hidden or 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
| 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