I am trying to have a recyclerview where each item is a simple TextView + Checkbox
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
/>
<CheckBox
android:id="@+id/chk"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
What I am trying to achieve is to (un)check the checkbox if it is clicked. But if the textview is clicked, then do the ripple animation on the entire item and start a fragment transition.
I couldn't find an example online and the closest that I found was RecyclerView onClick
I managed to get the onclick to function however, in the code
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView));
return true;
}
return false;
}
The problem I have is that the childView returned is the linearlayout and not the textview or checkbox. I am thus unable to determine whether the click was done on the textview or the checkbox.
Is there something that I am missing? Ideally if someone has a working example of how to implement this, that would be great.
Thanks.