1

I got a problem with SwithCompat, its working only on double tap
Im using next layout in 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>

So, the question is, how to make it work on a single tap?

UPD: RecItemClickListener code

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) { }
}

I think the problem is in "public boolean onSingleTapUp", so any ideas how to exclude header from this listener?

dennes544
  • 256
  • 3
  • 18
  • 1
    obviously you should not steal "clickability" in parent layout – Selvin Mar 18 '15 at 13:48
  • @Selvin i just tried to add/remove clickable flag to all layouts, and i found one more thing: even simple button works only with double tap – dennes544 Mar 18 '15 at 13:51
  • hmmm Scrollable(RecycleView) also stealing clickability ... you should play with descendants focusability – Selvin Mar 18 '15 at 13:56
  • @Selvin okay i found a problem, it was in RecyclerViewItemClickListener (custom listener), i will add this code to the question right now, i think problem is in public boolean onSingleTap, can u help me? – dennes544 Mar 18 '15 at 13:59

0 Answers0