ViewFlipper有几个ListViews

时间:2012-05-07 16:45:43

标签: android listview viewflipper

我是Android开发的新手,我正在尝试实现一种方式来显示6个可以用手势更改的视图(左右投掷,左右投掷)并使用以下ListView {{ 3}}。 6个视图具有相同的结构,但内容不同。这就是为什么我认为使用ViewFlipper的 Pull-To-Refresh-Listview 应该足够并且在Fling上 ,只应替换View的内容?

main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E1E1E1"
android:orientation="vertical"
android:scrollbars="vertical" >

    <ViewFlipper
        android:id="@+id/viewFlipper"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <com.markupartist.android.widget.PullToRefreshListView
            android:id="@+id/listView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#AB1A1A"
            android:textColor="#FFFFFF" >
        </com.markupartist.android.widget.PullToRefreshListView>

    </ViewFlipper></LinearLayout>

MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    m_objSeparatedListAdapter = new SeparatedListAdapter(this);
    m_objPullToRefreshListView = (PullToRefreshListView) findViewById(R.id.listView);

    m_linkedListDays.add("Te");
    m_linkedListMeals.add("st");

    ArrayAdapter<String> listadapter = new ArrayAdapter<String>(this, R.layout.list_item, m_linkedListMeals);
    for (int i = 0; i < m_linkedListDays.size(); i++) {
        m_objSeparatedListAdapter.addSection(m_linkedListDays.get(i), listadapter);
    }
    m_objPullToRefreshListView.setAdapter(m_objSeparatedListAdapter);

    m_objPullToRefreshListView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // GET DATA
        }
    });

    m_objPullToRefreshListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // FORWARD TO THE OTHER VIEW
            return true;
        }
    });

    m_objAnimationLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
    m_objAnimationLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
    m_objAnimationRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
    m_objAnimationRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);

    m_objGestureDetector = new GestureDetector(new MyGestureDetector());
    m_objPullToRefreshListView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return m_objGestureDetector.onTouchEvent(event);
        }
    });
}

MyGestureDetector

class MyGestureDetector extends SimpleOnGestureListener{ 

    DisplayMetrics dm = getResources().getDisplayMetrics();
    private int REL_SWIPE_MIN_DISTANCE = (int)(120.0f * dm.densityDpi / 160.0f + 0.5); 
    private int REL_SWIPE_MAX_OFF_PATH = (int)(250.0f * dm.densityDpi / 160.0f + 0.5);
    private int REL_SWIPE_THRESHOLD_VELOCITY = (int)(200.0f * dm.densityDpi / 160.0f + 0.5);

    // Detect a single-click and call my own handler.
    @Override 
    public boolean onSingleTapUp(MotionEvent e) {
        ListView lv = (PullToRefreshListView) m_objViewFlipper.getCurrentView();
        int pos = lv.pointToPosition((int)e.getX(), (int)e.getY());
        myOnItemClick(pos);
        return false;
    }

    @Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (Math.abs(e1.getY() - e2.getY()) > REL_SWIPE_MAX_OFF_PATH) return false;

        if (e1.getX() - e2.getX() > REL_SWIPE_MIN_DISTANCE && 
            Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) { 
            onRTLFling();
            m_objViewFlipper.setInAnimation(m_objAnimationLeftIn);
            m_objViewFlipper.setOutAnimation(m_objAnimationLeftOut);
            m_objViewFlipper.showNext();
        } else if (e2.getX() - e1.getX() > REL_SWIPE_MIN_DISTANCE && 
            Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) { 
            onLTRFling();
            m_objViewFlipper.setInAnimation(m_objAnimationRightOut);
            m_objViewFlipper.setOutAnimation(m_objAnimationRightIn);
            m_objViewFlipper.showPrevious();
        }

        return false; 
    } 
}

所以,问题是如何使用ONE Pull-To-Refresh-Listview管理多个视图(6)还包括fling手势?

感谢您的时间和帮助!

0 个答案:

没有答案