You can easily achieve this by using an interface
class ExercisesAdapter constructor(val mItemClickListener:ItemClickListener) : RecyclerView.Adapter() {
interface ItemClickListener{
fun onItemClick(position: Int)
fun onLongClick(position: Int)
}
inner class MyViewHolder(view:View): RecyclerView.ViewHolder(view){
init {
view.setOnClickListener{
mItemClickListener.onItemClick(adapterPosition)
}
view.setOnLongClickListener{
mItemClickListener.onLongClick(adapterPosition)
return@setOnLongClickListener true
}
}
}
}
From your MainActivity
public class MainActivity : ActionBarActivity(), ExercisesAdapter.ItemClickListener {
protected override fun onCreate(savedInstanceState: Bundle?) {
// set content view etc go above this line
mAdapter = ExercisesAdapter(this)
}
override fun onItemClick(position: Int) {
Toast.makeText(this@MainActivity, "TEST: " + position, Toast.LENGTH_SHORT).show()
}
override fun onLongClick(position: Int) {
//do long click here
}
}