January 2018
Intermediate to advanced
434 pages
14h 1m
English
We can use Anko, a library by Kotlin to reduce the code even further. Anko provides an onClick() method that accepts a lambda that gets executed onClick event:
class HelloWorldActivity2 : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) setSupportActionBar(toolbar) supportActionBar?.title = "Let's click" btn1.onClick { toast("Button 1 has been clicked by you! One") } btn2.onClick { toast("Button 2 has been clicked by you! Two") } btn3.onClick { toast("Button 3 has been clicked by you! Three") } }}
Read now
Unlock full access