我想有一个recyclerview其中每个项目是一个简单的TextView +复选框的Android Recyclerview多的onclick项目
<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>
我所试图实现的是一个(不)选中复选框,如果点击它。但是,如果单击textview,然后对整个项目执行涟漪动画并开始片段转换。
我不能在网上找到一个例子,我发现最接近的是RecyclerView onClick
我设法得到的onclick然而功能,在代码
@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;
}
的我遇到的问题是返回的childView是linearlayout而不是textview或复选框。因此我无法确定点击是在textview还是复选框上完成的。
有什么,我失踪?理想情况下,如果有人有一个如何实施这个实例的工作示例,那就太好了。
谢谢。
为什么不为该视图设置正常的听众? – pskink 2015-01-31 18:40:32
因为我喜欢默认情况下ripple效果recyclerview。但是,是的,它开始越来越像我必须单独做它们,然后单击textview以对复选框也起作用。 – AndroidP 2015-01-31 18:53:02