Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onfling and OnTouch does not work together

I have an Expandable Listview. I am implementing a deletion of the listItem on Swipe Left of each item.

I am using custom adapter for populating listview items.

public class InsightsListAdapter extends BaseExpandableListAdapter {
@Override
public View getGroupView(final int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    View row = convertView;
    row = inflater_.inflate(R.layout.insight_list_item, null);

    final GestureDetector gdt = new GestureDetector(new GestureListener());
    row.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            swipedViewPosition_=groupPosition;
            swipedView_=v;
            gdt.onTouchEvent(event);
            return true;
        }
    });

    return row;
}

I am using GestureListener like below

private static final int SWIPE_MIN_DISTANCE = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

private class GestureListener extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
            System.out.println("Left swiped--------");
            removeListItem();
            return false; // Right to left
        }  
        return false;
    }

}

As it is a Expandable Listview i implemented some click functionalities in the acticity

        insightList_.setOnGroupClickListener(new OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v,
                    int groupPosition, long id) {
                System.out.println("Group clicked---------");
                showClear(true);
                selectedItem_ = null;

                return false;
            }
        });

But now on OnFling is getting called. but not OnGroupClick()

When i return false from onTouch event function from adapter, OnGroupClick is getting called but not OnFling().

Either Fling will work or OnGroupClick but not both simultaneously.

like image 729
John Avatar asked Nov 11 '22 16:11

John


1 Answers

On ontouch event of the row

row.setOnTouchListener(new OnTouchListener() {[..]

you return true, so no more touch event will be called after that, change to return false and the touch event will be downfall to the next child view.

like image 176
Sulfkain Avatar answered Nov 14 '22 23:11

Sulfkain