12

I have the new datepicker implemented in an fragment. This is wrapped in a scrollview. When trying to use the datepicker i have to click and hold somewhere on the screen before i can scroll through the datepickers calader to let's say may.

is there a way to fix this?

im using this timepicker: enter image description here

And im loading it like this:

 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView2"
    android:layout_row="11"
    android:fillViewport="true"
    android:background="#162229"
    android:layout_column="2"
    android:paddingBottom="20dp">
<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="#162229"

    android:orientation="vertical" >

    <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:background="#162229"
        android:calendarTextColor="#fff"
        android:layout_height="wrap_content"

        android:calendarViewShown="false" > <!-- style="@style/date_picker_style" -->
    </DatePicker>
</LinearLayout>
</ScrollView>
Twizzler
  • 491
  • 1
  • 7
  • 25
  • I had the same problem, unfortunately I had to use a DatePickerDialog and it works without any problem. [Good example](http://pulse7.net/android/date-picker-dialog-time-picker-dialog-android/) and [another example](http://androidopentutorials.com/android-datepickerdialog-on-edittext-click-event/) – Juan Saravia May 02 '15 at 20:17
  • 2
    i too had the same issue. That time i used **bold'android:datePickerMode="spinner"' ** to avoid the issue. But the look and feel will not get – Sanu May 13 '15 at 04:38
  • My best guess is that the scrollview parent is trapping the gestures and they need to be handled by the DatePicker before the ScrollView gets them. I'm afraid I may wind up just going with the DatePickerDialog option as well. – Norman H Nov 23 '15 at 16:55

3 Answers3

16

Create a class that extends DatePicker and override the following method:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN)
    {
        ViewParent p = getParent();
        if (p != null)
            p.requestDisallowInterceptTouchEvent(true);
    }

    return false;
}

It'll work fine. source : here

Community
  • 1
  • 1
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
0

This is because of the parent ScrollView component. Either remove the scroll view or use date picker dialog.

Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24
0

For me, this was useful: How to disable and enable the scrolling on android ScrollView?

Custom scroll view that you lock when appropriate

Community
  • 1
  • 1
hmac
  • 267
  • 3
  • 9