0

I have a viewflipper with two linear layouts. If I just have some text in each linear layout, I can swipe between layouts perfectly fine. I added a listview to the first layout and when I try to swipe to the next layout over this listview it doesn't detect it. How can I fix this? Thanks!

Activity

public class MainActivity extends Activity {
private ViewFlipper vf;
private float lastX;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    vf = (ViewFlipper) findViewById(R.id.view_flipper);

    ListView listView = (ListView) findViewById(R.id.listView1);
    String[] values = new String[] { "1", "2", "3", "4", "5", "6", "7", "8" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, values);
    listView.setAdapter(adapter);
}

@Override
public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        lastX = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        float currentX = touchevent.getX();
        if (lastX < currentX) {
            if (vf.getDisplayedChild() == 0)
                break;
            vf.setInAnimation(this, R.anim.in_from_left);
            vf.setOutAnimation(this, R.anim.out_to_right);
            vf.showNext();
        }
        if (lastX > currentX) {
            if (vf.getDisplayedChild() == 1)
                break;
            vf.setInAnimation(this, R.anim.in_from_right);
            vf.setOutAnimation(this, R.anim.out_to_left);
            vf.showPrevious();
        }
        break;
    }
    }
    return false;
}
}

Layout

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

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="View Flipper Test" />

<ViewFlipper
    android:id="@+id/view_flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="6dip" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="0dp"
            android:dividerHeight="10.0sp" >
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Blank Layout!"
            android:textColor="#00ff00"
            android:textSize="14sp"
            android:textStyle="bold" >
        </TextView>
    </LinearLayout>
</ViewFlipper>

</LinearLayout>
user1282637
  • 1,827
  • 5
  • 27
  • 56

0 Answers0