문제

Dear Android hackers, I am attaching a gestureListener recognizing flings to a ListView. The rows of the ListView consist of a LinearView and some TextViews. Unfortunately, the fling is not detected, when it starts on one of the TextViews:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#000000" >
        <TextView
            android:id="@+id/author"
            android:textSize="14sp"
            android:textColor="#ffffff"
            android:textStyle="bold"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/date"
            android:textSize="11sp"
            android:textColor="#eeeeee"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"/>
    </LinearLayout>
    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dp"
        android:paddingRight="5dp"
        android:paddingLeft="5dp"
        android:textColor="#333333"

        android:paddingBottom="5dp"
        android:textSize="14sp"
        android:layout_weight="2"/>
</LinearLayout>

So, when I start the fling on the horizontal LinearLayout, everything works fine, but when I start it on the TextView at the bottom, nothing happens. It containts editable text, if that could be the problem... As is said, the Listener is attached to the ListView itself.

I'd be glad if somebody could help!

Jan Oliver

도움이 되었습니까?

해결책

Your editable TextView is returning true from onTouch(), preventing the event from being processed by the LinearLayout higher up the view hierarchy.

There is nothing stopping you attaching a custom OnTouchListener to your TextView to override this and pass the event to your existing GestureDetector.

textView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View arg0, MotionEvent ev) {             
        return gestureDetector.onTouchEvent(ev);
    }           
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top