1

私はAndroid開発に不慣れで、ジェスチャー(左右フリング、右左フリング)で変更できる6つのビューを表示し、次のListViewプルトゥリフレッシュを使用する方法を実装しようとしています。 -リストビュー。6つのビューの構造は同じですが、内容が異なります。そのため、ViewFlipperを使用したPull-To-Refresh-Listviewで十分であり、Flingでは、ビューのコンテンツのみを置き換える必要があると思いますか?

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; 
    } 
}

それで、再び問題は、フリングジェスチャも含む1つのPull-To-Refresh-Listviewで複数のビュー(6)を管理する方法ですか?

お手数をおかけしますが、よろしくお願いいたします。

4

0 に答える 0