From 8326fd32d94eec6deef5efa3fb1cb1d3ab0fd10a Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 26 Feb 2020 01:35:13 +0800 Subject: [PATCH] :pencil2: Add the OnScrollListener example --- README.md | 10 ++++++++++ .../com/shawnlin/numberpicker/sample/MainActivity.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index e3f7458..7b61393 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,16 @@ numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() Log.d(TAG, String.format(Locale.US, "oldVal: %d, newVal: %d", oldVal, newVal)); } }); + +// OnScrollListener +numberPicker.setOnScrollListener(new NumberPicker.OnScrollListener() { + @Override + public void onScrollStateChange(NumberPicker picker, int scrollState) { + if (scrollState == SCROLL_STATE_IDLE) { + Log.d(TAG, String.format(Locale.US, "newVal: %d", picker.getValue())); + } + } +}); ``` #### XML diff --git a/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java b/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java index 140cc4d..8dded0c 100644 --- a/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java +++ b/sample/src/main/java/com/shawnlin/numberpicker/sample/MainActivity.java @@ -102,6 +102,16 @@ public void onValueChange(NumberPicker picker, int oldVal, int newVal) { Log.d(TAG, String.format(Locale.US, "oldVal: %d, newVal: %d", oldVal, newVal)); } }); + + // OnScrollListener + numberPicker.setOnScrollListener(new NumberPicker.OnScrollListener() { + @Override + public void onScrollStateChange(NumberPicker picker, int scrollState) { + if (scrollState == SCROLL_STATE_IDLE) { + Log.d(TAG, String.format(Locale.US, "newVal: %d", picker.getValue())); + } + } + }); } }