January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's go through the given steps to create an alert dialog with a list of items.
Anko provides selectors for creating a dialog with a list of items. Selectors are very easy to use. You just need to provide the title of alert dialog, the list, and the lambda that will be executed when an option is selected. Here's an implementation of it:
val companies = listOf("Google", "Microsoft", "HP", "Apple")selector("Where do you work?", companies, { dialogInterface, i -> toast("So you work at ${companies[i]}, right?")})
That's all folks! It's really simple and concise. So, in the preceding example, if you click on the list item, you will see a toast with a message that says "So you work at Google, right?"
Read now
Unlock full access