
Running applications on Android 3.2 or higher versions , the DatePicker are the new ones where you can also scroll on the day, the month and the year.

The problem that occurs in these versions of Android is when you use a DatePicker in a ScrollView and try so scroll down for example the day from 30 to 10.
At first, it will be fine and the scrolling will be smoothly. But then, it simply blocks, and when you try to scroll/swipe again, only a few pixels will move.
The reason of this problem is simple : the ScrollView is intercepting and stealing the touch events once your finger moves outside of the Date/Time Picker controls. A simple work-around is to create a subclass of DatePicker where you prevent the parent from stealing events after the initial touch down on your Picker. Here is the code :
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewParent;
import android.widget.DatePicker;
public class CustomDatePicker extends DatePicker
{
public CustomDatePicker(Context context, AttributeSet attrs, int
defStyle)
{
super(context, attrs, defStyle);
}
public CustomDatePicker(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public CustomDatePicker(Context context)
{
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
/* Prevent parent controls from stealing our events once we've
gotten a touch down */
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
{
ViewParent p = getParent();
if (p != null)
p.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
Now, you can use your CustomDatePicker in your Java classes. If you want to use it directly in your XML layout, you can do it using custom view :
If you have any questions, I would be happy to answer :)
Source
Commentaires
#1 • Le 10 septembre 2012 à 22:56, hotel paris a dit :
#2 • Le 23 octobre 2012 à 10:42, cheap 10 tablet pc a dit :
#3 • Le 28 novembre 2012 à 00:39, Pont a dit :
#4 • Le 28 février 2013 à 04:58, pipo u1 a dit :
#5 • Le 28 février 2013 à 06:23, haier w718 a dit :
#6 • Le 07 mars 2013 à 04:08, ds708 a dit :