I ran into a problem where I had a simple ListView in a BottomSheet and ListView had enough items to fill the screen and scroll even m
This is the correct list view custom class with touch event hadnling
public class BottomSheetListView extends ListView
{
public BottomSheetListView(Context context, AttributeSet p_attrs)
{
super(context, p_attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (canScrollVertically(this))
{
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
if (canScrollVertically(this))
{
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onTouchEvent(ev);
}
public boolean canScrollVertically(AbsListView view)
{
boolean canScroll = false;
if (view != null && view.getChildCount() > 0)
{
boolean isOnTop = view.getFirstVisiblePosition() != 0 || view.getChildAt(0).getTop() != 0;
boolean isAllItemsVisible = isOnTop && view.getLastVisiblePosition() == view.getChildCount();
if (isOnTop || isAllItemsVisible)
{
canScroll = true;
}
}
return canScroll;
}
}