Skip to content

Instantly share code, notes, and snippets.

@rvdlesk
Forked from izmajlowiczl/CustomDatePicker.java
Created December 18, 2016 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvdlesk/721f73cb3d9374de1f26b9b06a3fbb2d to your computer and use it in GitHub Desktop.
Save rvdlesk/721f73cb3d9374de1f26b9b06a3fbb2d to your computer and use it in GitHub Desktop.
Date/Time Picker fix for ScrollView
package com.mydriver.customer.ui.common.custom;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewParent;
import android.widget.DatePicker;
/**
* Custom implementation of {@link DatePicker} to fix issue with {@link android.widget.ScrollView}.
* Disallows touch event for parent when touched on picker.
*
* Creator: <lukasz.izmajlowicz@mydriver.com>
* Date: 9/19/13
*
*/
public class CustomDatePicker extends DatePicker {
public CustomDatePicker(Context context) {
super(context);
}
public CustomDatePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomDatePicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
ViewParent parentView = getParent();
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (parentView != null) {
parentView.requestDisallowInterceptTouchEvent(true);
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment