Skip to content

Instantly share code, notes, and snippets.

@izmajlowiczl
Created September 20, 2013 04:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save izmajlowiczl/6633221 to your computer and use it in GitHub Desktop.
Save izmajlowiczl/6633221 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;
}
}
@TechlogicMinds
Copy link

Thanks a lot ....It really works....:)

@GeoffreyHinck
Copy link

@curliq
Copy link

curliq commented Jun 8, 2016

Do you have a CustomTimePicker too? :D
Or does this work for both?
I know I'm lazy for not trying.
please don't judge me

@creativedrewy
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment