Listview Swipe inside viewflipper

后端 未结 3 524
旧巷少年郎
旧巷少年郎 2021-01-03 09:39

Im trying to swipe left and right on a listview and get the viewflipper to swtich. Just like the remeberthemilk app and the default news and weather app on the nexus one (Sw

3条回答
  •  一向
    一向 (楼主)
    2021-01-03 10:20

    Here is the way i use. it is prety simple.

    When you assign onTouchListener to ViewFlipper, create reference for that listener first.

    public class ViewFlipperTouchListener implements OnTouchListener {
       ....
       ......
    }
    
    
    ViewFlipperTouchListener listener = new ViewFlipperTouchListener ();
    
    mViewFlipper.setOnTouchListener(listener);
    
    
    
    //now you have reference to listener. use it to send on touch event.
    
    
    mListView.setOnTouchListener(new OnTouchListener(){
    
      @Override
      public boolean onTouch(View v, MotionEvent event){
         listener.onTouch(v, event);
     return false;
      }
    });
    

    i simply delegated MotionEvent to viewflipper's onTouchListener by using reference "listener". And return false to imply that event is not consumed on ListView. This will help you to scroll down/up on listview and delegates everything (scroll down/up and swipe left/right ...etc to listener.)..

    Believe it. it works nice :D

提交回复
热议问题