views:

101

answers:

2

This is maddening. I have the following XML layout:

<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/shadow" android:focusable="true" android:focusableInTouchMode="true">
    <ViewFlipper android:id="@+id/flipper" android:layout_width="fill_parent" android:layout_height="fill_parent">
        <EditText android:id="@+id/reviews" style="@style/DescriptionArea" android:layout_width="fill_parent" android:layout_height="wrap_content" android:enabled="false" android:background="@null" />
     <EditText android:id="@+id/notes" style="@style/DescriptionArea" android:hint="@string/detail_hint" android:layout_width="fill_parent" android:layout_height="wrap_content" android:enabled="false" android:maxLines="4"/>
    </ViewFlipper>
</FrameLayout>

And the Java:

viewFlipper = (ViewFlipper)findViewById(R.id.flipper);
    slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
    slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
    slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
    slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);

    gestureDetector = new GestureDetector(new MyGestureDetector());
    gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    };

It seems like if I try to fling on top of the EditText area, the gesture does not register. However, if I fling around it, that is, the background of the EditText, it DOES work. I've tried following around with the fill_parent/wrap_content heights and widths, but it doesn't seem to change a thing. I've confirmed this suspicion my making the EditText background "red," and noting that nothing within that red rectangle can activate a fling. So how do I make this work?

+2  A: 

You may override activity's dispatchTouchEvent method:

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (gestureDetector != null) {
        gestureDetector.onTouchEvent(ev);
    }
    return super.dispatchTouchEvent(ev);
}

Obviously gestureDetector is a member variable you need to declare and initialize on your activity.

Konstantin Burov
How terrible! I was only overriding onTouchEvent: @Override public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) return true; else return false; }Thanks for your help. Would upvote a hundred times if I could.
GJTorikian
A: 

try to apply setLongClickable(true) for the ViewFlipper

jakk