Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NumberPicker on ScrollView doesn't scroll on Android 4.0.4

I am trying to use Number picker on activity with parent as Scrollview. Since there are two number pickers arranged vertically. But number picker doesn't scroll properly on Android 4.0.4; though it works well on Android 4.1.2

I even tried to remove one number picker, so that scroll view hides by itself, to see the behavior. But still seeing the same. The numberPicker doesn't change values and get stuck. Though up and down arrows work well, in both the cases.

Without scrollView in place, it works well.

Please help.

like image 404
Sonia Avatar asked Sep 03 '26 07:09

Sonia


1 Answers

I know this is an old question, still...

This works for me:

numberPicker.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(final View v, final MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE && v.getParent() != null) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
            v.performClick();
        }

        v.onTouchEvent(event);
        return true;
    }
});
like image 62
User42 Avatar answered Sep 04 '26 21:09

User42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!