How I can use callback in Kotlin?

后端 未结 7 2169
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:25

    define a function like this:

      fun performWork(param1: String, myCallback: (result: String?) -> Unit) {
        // perform some network work
    
        // on network finished
        myCallback.invoke("result from network")
      }
    

    use like this:

      performWork("http://..."){ result ->
      //use result
      }
    

提交回复
热议问题