Swipe detection for each row of listview

后端 未结 6 723
长情又很酷
长情又很酷 2021-02-18 16:32

I have a list of videos located in the sd-card. At this point, I just need help in creating gestures or swipe detection for each row in the list view. Thanks to this question at

相关标签:
6条回答
  • 2021-02-18 16:56

    I'm using the per item approach in my solution - take a look here My swipe detection code might be a bit different from standard swipe detection but it works perfectly for me. And I'm using attached tags to get the item related data. Hope that helps, but if you do have some questions just let me know and I'll try to explain in more detail.

    0 讨论(0)
  • 2021-02-18 16:58

    I think what you're looking for is SwipeView (or perhaps even ViewFlow) rather than standard Android gesture detection.

    0 讨论(0)
  • 2021-02-18 17:03

    Take a look into this answer and use pointToPosition method inside onFling Event

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
            Toast.makeText( listAdapter.getItem( listView.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())).toString());
            return super.onFling();
        } catch( Exception e ) {
            // do nothing
        }
    }
    
    0 讨论(0)
  • 2021-02-18 17:04

    This question is old, but by now thankfully Jake Wharton backported some code released for ICS here; this should allow you to swipe individual rows: https://github.com/JakeWharton/SwipeToDismissNOA

    0 讨论(0)
  • 2021-02-18 17:09

    As Per My Opinion is Use Boolean for the item,When that item is touched set as true,Using onTouchListener,

    ListItem.setOnTouchListener(new View.OnTouchListener() {
    
            @Override
            public boolean onTouch(View arg0, MotionEvent event) {
                click=true;
                return click;
    
    
            }
    
        });`
    

    Then You Can Override This:

     @Override
    public boolean dispatchTouchEvent(MotionEvent ev){
    super.dispatchTouchEvent(ev);
    Log.v("Inside", "=====Dispatch Event===");
    if(click){
        Log.v("Inside", "=====Dispatch Event=T==");
        click=false;
         return gestureDetector.onTouchEvent(ev);
    
    }else{
        return false;
    }
    
    }
    
    0 讨论(0)
  • 2021-02-18 17:15

    We implemented swipe detection per row for revealing actions and dismissing items here https://github.com/47deg/android-swipelistview . I hope it helps

    0 讨论(0)
提交回复
热议问题