January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's create a few buttons in our layout, clicking on them will show a toast:
toast("a toast message")toast(R.string.message_string)longToast("a long duration toast message")
I suggest that you try showing toasts on the click of a button on your own, before moving on to the solution. Let's make a layout with three buttons that show toast on clicking using the preceding syntaxes.
The following is one way of creating a layout with three buttons where we have put our code to show toast inside onClick listener of the buttons. You can also put your layout in an external class that implements the AnkoComponent interface:
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ...Read now
Unlock full access