我遇到了SwithCompat的问题,它只能在双击上工作 我在recyclerview headerview中使用下一个布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="175dp"
android:background="@drawable/default_wallpaper"
android:orientation="vertical"
android:weightSum="1">
<ru.dennes544.villias.Customs.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginStart="16dp"
android:id="@+id/circleView"
android:layout_above="@+id/linearLayout"
android:layout_alignParentStart="true" />
...
..
.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/circleView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:clickable="true">
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch1"
android:padding="10dp" />
</RelativeLayout>
</RelativeLayout>
所以,问题是,如何让它在一次点击工作?
UPD: RecItemClickListener代码
public class RecItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
public interface OnItemClickListener {
public void onItemClick(View view, int position);
}
GestureDetector mGestureDetector;
public RecItemClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}
@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;
}
@Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }
}
我认为问题出现在“public boolean onSingleTapUp”中,所以如何从这个监听器中排除标题?