recyclerview item click listener in activity kotlin code example
Example 1: onclicklistener recyclerview only first item worked problem kotlin
override fun onItemClicked(position: Int, view: View) {
when (view.id) {
R.id.btn_cat_delete -> {
}
R.id.btn_cat_add_words -> {
}
R.id.btn_cat_all_diktat -> {
}
R.id.btn_cat_edit -> {
}
}
Example 2: how to set onClickListener to RecyclerView kotlin
private fun CreateRecyclerView(){
val recycler_list = findViewBiId<RecyclerView>(R.id.myRecyclerViewId)
recycler_list.setOnTouchListener { v, _ ->
if (layoutAttachment.visibility == View.VISIBLE || menuButtons.visibility == View.VISIBLE) {
closeOpenDialogs()
v.performClick()
} else {
false
}
}
recycler_list.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recycler_list.setHasFixedSize(true)
recycler_list.adapter = myAdapter
recycler_list.itemAnimator = DefaultItemAnimator()
}
private fun closeOpenDialogs(){
if (layoutAttachment.visibility == View.VISIBLE || menuButtons.visibility == View.VISIBLE) {
layoutAttachment.visibility == View.GONE
menuButtons.visibility == View.GONE
}
}