Home > other >  onClickListener on Whole Recylcerview doesn't work
onClickListener on Whole Recylcerview doesn't work

Time:11-15

In xml,

        <androidx.recyclerview.widget.RecyclerView
            android:id="@ id/itemRecyclerview"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clickable="true"/>

In onCreateView in Fragement,

    binding.apply {
        itemRecyclerview.setOnClickListener {
            NavigateWithItemname(itemname)
            Log.i("click","click") //doesn't work
        }
    }

setOnClickListener on whole RecylcerView doesn't work. ( I don't see click Log in logcat )

I don't know why...

CodePudding user response:

Use onClickListener on ItemView this will help to navigate through position wise:

holder.itemView.setOnClickListener(v -> {
       if(position==0){
            openFragmentA();
       }else if(position == 1){
            openFragmentB();
    }else{  
            openFragmentC();
    }
    
    });
  • Related