Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过点击的方式切换,没有滑动回调。 #84

Open
guominfang opened this issue Jun 19, 2023 · 4 comments
Open

通过点击的方式切换,没有滑动回调。 #84

guominfang opened this issue Jun 19, 2023 · 4 comments

Comments

@guominfang
Copy link

我是直接使用:
<com.loper7.date_time_picker.number_picker.NumberPicker android:id="@+id/dateTimePicker2" android:layout_width="match_parent" android:layout_height="@dimen/dp_50" android:layout_marginTop="@dimen/dp_12" app:layout_constraintTop_toBottomOf="@id/tv_tip_cl2" app:np_dividerColor="@android:color/transparent" app:np_max="40" app:np_min="1" app:np_orientation="horizontal" app:np_selectedTextColor="@color/vm_color_brand_hover" app:np_selectedTextSize="@dimen/sp_16" app:np_textColor="@color/vm_color_text_01" app:np_textSize="@dimen/sp_14" app:np_value="12" app:np_wheelItemCount="7" app:np_wrapSelectorWheel="false" />

  1. 通过点击的方式切换,选项,无法正确的选中点击的选项,同时setOnScrollListener方法没有回调。

建议公开:mScrollState属性,如果我通过setOnValueChangedListener的值来获取选中的选项,会回调太频繁

@guominfang
Copy link
Author

实际问题,是滑动状态错误

@loper7
Copy link
Owner

loper7 commented Jun 21, 2023

不太理解你说的意思
如果你想在任何时候获取picker的值 可以通过picker.value 来获取

@guominfang
Copy link
Author

guominfang commented Jun 25, 2023

场景是这样的:
需求:在控件滑动切换结束时,获取当前值的。

方案1: 我设置了setOnScrollListener来监听控件的滑动状态,但是,当前我通过点击,控件会自动切换下一项,但是没有触发scrollListener回调

方案2: 通过设置setOnValueChangedListener,来监听最新值,但是这个回调太频繁,而且这里有问题,例如:原本是选项是2,通过点击切换,最新值会回调:3->2->3,回调三次

所以,有什么方案可以获取到,控件停止滑动时,当前的值吗

`

    binding.dateTimePicker2.setOnScrollListener((view, scrollState) -> {
        Log.d("gmf", "showStreamerdelayCl2: scrollState=" + scrollState);
        Log.d("gmf", "showStreamerdelayCl2: " + view.getValue());
        if (scrollState == SCROLL_STATE_FLING) {
        }
    });

    binding.dateTimePicker2.setOnValueChangedListener((picker, oldVal, newVal) -> {
                Log.d("gmf", "showStreamerdelayCl2: oldVal= " + oldVal);
                Log.d("gmf", "showStreamerdelayCl2: newVal=" + newVal);
                Log.d("gmf", "showStreamerdelayCl2: newVal=" + (int) (newVal / 2f * 1000));
            }
    );

`

@loper7
Copy link
Owner

loper7 commented Jun 25, 2023

这个目前没有很好的方法解决,如果你接受不了方案二频繁回调的话,我的建议是自己使用numberpicker类似的控件替换掉控制器内的numberpicker,因为仓库内的numberpicker是基于android number picker来修改的,这段时间比较忙,所以可能没有充足的时间来更新。
在手动点击触发值发生变更的时候调一下onScrollStateChange,这样应该可以比较友好的处理方案1的问题,你有时间的话,可以pull代码修改自己使用~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants