Reputation: 8946
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.
Upvotes: 5
Views: 739
Reputation: 5119
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.
Upvotes: 1