Monday, 14 May 2018

Interface in Android (kotlin)


RecyclerViewClick.kt
interface RecyclerViewClick {
    fun onItemClick(position: Int)

}



// declare interface in activity

internal var recyclerListener: RecyclerViewClick = object : RecyclerViewClick {

    override fun onItemClick(position: Int) {

         // do you stuff

    }
}


// connection between two class using interface

// first place
adapter = ArtistSelectListAdapter(context, artistList, recyclerListener, true)


// for call interface
holder.rlTop.setOnClickListener(View.OnClickListener {
    recyclerListener.onItemClick(position) // this line call interfacewhere declare

})



No comments:

Post a Comment

Run/install/debug Android applications over Wi-Fi ?

Open Teminal/cmd --------------- Below steps is for Android 10 or lower Step 1 - Connect the device via USB and make sure debugging is work...