How I can use callback in Kotlin?

后端 未结 7 2164
Happy的楠姐
Happy的楠姐 2020-12-13 04:05

I have View and one CircleShape , which should show toast in this View. And I use it in main Activity. This is my interface

interface OnClickListenerInterfa         


        
相关标签:
7条回答
  • 2020-12-13 04:32

    Have you tried to use a lambda expression? For example in your case:

    mCircleShape.setOnClickListener( 
        { _ -> ToastUtils.showSuccessMessage(context,"pressed") }
    )
    

    Or if you want to make it more kotlin style:

    mCircleShape.listener = ( 
        { _ -> ToastUtils.showSuccessMessage(context,"pressed") }
    )
    
    0 讨论(0)
提交回复
热议问题