shawnlin013 / numberpicker Goto Github PK
View Code? Open in Web Editor NEW:slot_machine: The android library that provides a simple and customizable NumberPicker.
License: MIT License
:slot_machine: The android library that provides a simple and customizable NumberPicker.
License: MIT License
It is nice to be able to set the typeface using setTypeFace(). A corresponding getter would be helpful, so I can do something like
mNumberPicker.setTypeface(mNumberPicker.getTypeFace(), Typeface.BOLD);
Hello,
I get the following issue when using horizontal orientation:
java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6588) at android.widget.ListView.measureHeightOfChildren(ListView.java:1282) at android.widget.ListView.onMeasure(ListView.java:1182) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17547) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535) at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2615) at android.view.View.measure(View.java:17547) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2015) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1781) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I would like to ask how can I do this to show him 5 10 15 20 25 30 instead of 1 2 3 4 5 6 7 8 9 10
Since the places where API 16 calls are made, there is already check for
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
in the code, I think, minsdk should be 15 and not 16.
Hello!
Is there any chance to set number of currently visible rows except selected one?
Or is there any chance to hide all other rows except selected?
if I set
app:np_wheelItemCount="1"
when try to scroll the app crashes with IndexOutOfBounds exception
java.lang.ArrayIndexOutOfBoundsException: length=1; index=-1
at com.shawnlin.numberpicker.NumberPicker.incrementSelectorIndices(NumberPicker.java:1695)
WBR
Vadim
Hi there,
thanks for this lib. I got nuts on the bugs of the "native" one.
Right now I use the NumberPicker inside a FrameLayout, which is inflated into a DilaogFragment.
It would be nice to say android:layout_width="match_parent" in order to allow swiping next to the numbers. Then I want to say app:np_width="82dp" for quite a smale divider (only for visual purpose).
Best regards,
DaRolla
You've specified a string resource in your XML, how would that look?
If I disable the number picker programmatically, it will still scroll in response to touch events. This doesn't seem to happen when the orientation is vertical, only horizontal.
Looking for a way to show values in a step of 0.5.
e.g.
10.0 <- min
10.5
11.0
11.5
and so on..
Love the layout and everything, but unfortunately the text size scales with the np_height/width dimension. Here is how I tried to implement it.
<com.shawnlin.numberpicker.NumberPicker
app:np_height="30dp"
app:np_textSize="20sp"
android:id="@+id/snooze_duration_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:np_dividerColor="@color/colorSleepArc"
app:np_max="60"
app:np_min="0"
app:np_textColor="@color/colorAccent"
app:np_orientation="horizontal"
app:np_value="5"
android:layout_toEndOf="@+id/snooze_button"
app:np_typeface="sans-serif-thin"
/>
Hi
I don't seem to be able to set the orientation to vertical; I tried both modes, xml and java but the picker always render in horizontal.
Android 7.1.1 api25
hi ShawnLin013
i have a fragment with numberpicker
i call fragment and pass alarm.npminutes to it;
it has negative integer value , for example -19
this is my code:
private void showNpminutesDialog(final Alarm alarm) {
final FragmentTransaction ft = getFragmentManager().beginTransaction();
final Fragment prevx = getFragmentManager().findFragmentByTag("npminutes_dialog");
if (prevx != null) {
ft.remove(prevx);
}
ft.addToBackStack(null);
/* Create and show the dialog.*/
final npminutesDialogFragment newFragment =
npminutesDialogFragment.newInstance(alarm, alarm.npminutes, getTag());
newFragment.show(ft, "npminutes_dialog");
}
in fragment npminutesDialogFragment , i read alarm.npminutes by below ode:
final int npminutes = bundle.getInt(KEY_NPMINUTES);
then i create dialog with numberpicker as below
View v1x = getActivity().getLayoutInflater().inflate(R.layout.numberpicker, null);
picker = (NumberPicker) v1x.findViewById(R.id.horizontal_number_picker);
picker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// do your other stuff depends on the new value
}
});
picker.setValue(alarm.npminutes); // <========== -19
picker.setMinValue(-59);
picker.setMaxValue(59);
picker.setWrapSelectorWheel(false);
final AlertDialog alertDialog = new AlertDialog.Builder(context)
.setView (v1x)
.setPositiveButton(R.string.time_picker_set, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
set(alarm, tag);
}
})
.setNegativeButton(R.string.time_picker_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
})
.setTitle("select plus/minus minute for alarm time")
.create();
return alertDialog;
}
now when dialog opened with negative number , wheel show 20 instead -20
thanks alot for your library
And... just close this issue when you read it! :·)
Well i've tried using both getValue() and setting an onValueChangedListener both crash and burn "Null pointer Exception" ??
Hey,
It's a nice lib, thank you. I have a question can we make custom divider instead of the divider can we replace it with some circular view.
I set the string to numberpicker ,but when the string item is too long.It can't show string completely.
(e.g. "Bonaire, Sint Eustatius and Saba" ,in numberpicker only show "naire, Sint Eustatius and Sa")
========
我遇到一個問題是當我放入string到numberpicker裡,都可以正常顯示但是在字數較長的項目中,他就會致中顯示並且切掉頭尾的字。
When using np_formatter in xml or setFormatter() in java, all values except the first value are formatted correctly. However, when the user starts interacting with the NumberPicker the first value gets formatted.
String: <string name="number_picker_formatter">%1d ft</string>
XML:
<com.shawnlin.numberpicker.NumberPicker
android:id="@+id/number_picker_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:np_width="64dp"
app:np_height="180dp"
app:np_dividerColor="@color/colorPrimary"
app:np_formatter="@string/number_picker_formatter"
app:np_max="24"
app:np_min="1"
app:np_textSize="16sp"/>
Java:
NumberPicker widthNumberPicker = (NumberPicker) getDialog().findViewById(R.id.number_picker_width);
widthNumberPicker.setFormatter(R.string.number_picker_formatter);```
I changed the
android:layout_width="40dp"
android:layout_height="100dp"
all UI stuffs messed UP, other numbers are over lapping the divider!
<com.shawnlin.numberpicker.NumberPicker
android:id="@+id/number_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:np_width="64"
app:np_height="180"
app:np_dividerColor="@color/colorPrimary"
app:np_formatter="%02d"
app:np_max="7"
app:np_min="-7"
app:np_textColor="@color/colorPrimary"
app:np_textSize="30sp"
app:np_typeface="sans-serif-light" />
Caused by: java.lang.IllegalArgumentException: minValue must be >= 0
Is there a way to change the gap height between each value in the picker?
No enable/disable feature yet, for disabling the spin when waiting for submitting data?
I was able to disable the layout using ViewGroup instances and disabling the children, but NumberPicker still can be spin but feels like buggy, constantly spinning...
Can it be fixed?
Thank You..
Hi
How do you make it appear in multiples instead of 123456789?
Such as:
5 10 15 20 25 30 35 40 45 50
Or you can customize your data source
There are a bunch of pickers in a dialog, I want the selected value to be stored in an int value so that I can use for other stuff..! but it's not seem to be working with me..!?
I've tried this
PicValue_1 = numberPicker1.getValue();
Log.i("PicValue_1 TEST_1", "" + numberPicker1.getValue());
the log never showed..!
then I've tried this.
numberPicker1.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
PicValue_1 = newVal;
Log.i("PicValue_1 TEST_2", "" + numberPicker1.getValue());
Toast.makeText(MainActivity.this, "picker changed from " + numberPicker1.getValue() + "|" + oldVal + " to " + newVal , Toast.LENGTH_SHORT).show();
}
});
..But the log never showed again neither the toast..!? I tried to move the listener inside the dialog button event listener, but no luck..? what I'm doing wrong..!
Interesting, that since I have included the library to my project I have experiencing this crash:
http://stackoverflow.com/questions/36447078/setselection-on-a-spinner-crashes-when-layout-weight-is-assigned-to-spinner/38790474#38790474
If I remove the library the crash disappears.
I have found a workaround and don't understand the coherency but I am preatty sure in this issue so I wanted to share. I have posted my workaround to the stackoverflow post.
When setting min/max values for the number picker, the global boolean for wrapping the selector wheel is overwritten by the following lines:
boolean wrapSelectorWheel = mMaxValue - mMinValue > mSelectorIndices.length; setWrapSelectorWheel(wrapSelectorWheel);
scroll fast, then long press fast on some item. repeat. the scroll won't snap to the closest value
I'm not sure if this is the intended behaviour. If it is, just close the issue.
It seems like the initial value is blank when i'm using a formatter:
It functions fine, but the value only appears after I've spun the number picker.
When I don't specify a formatter, it works fine:
The formatter I have is very simple - I just need increments of 5 instead of 1:
class StepFormatter implements com.shawnlin.numberpicker.NumberPicker.Formatter {
@Override
public String format(int value) {
return "" + value*5;
}
};
能否改动分割线选择器内的字体颜色和分割线以外的字体颜色,为两种颜色,视觉效果上看起来一目了然,便以区分
I great, you component, is posible set view in horizontal mode¿?
Steps to reproduce:
number_picker
and set:app:np_wheelItemCount="5"
app:np_wrapSelectorWheel="false"
Only way to escape the top/bottom position is with a fast fling.
See video for demo:
NumberPicker_NoWrap_ItemCount5_tripping.zip
What method returns the selected number value?
Hi I have been not been able to get the fading edges to work. I have tried both in xml and in code.
android:fadingEdgeLength="10dp"
android:fadingEdge="horizontal"
android:fadeScrollbars="true"
snoozeDurationPicker.setHorizontalFadingEdgeEnabled(true);
Thanks
Steps to reproduce:
number_picker
and set:app:np_wheelItemCount="7"
app:np_wrapSelectorWheel="false"
I wasn't able to get ANR with the value of 6 or lower.
I Need to display more than 3 items, How can I do this?
Hi,
As the title says, divider thickness can only be set in xml, because mSelectionDividerThickness
is private.
Thanks.
i wana use number picker for choosing weight so how to use floating numbers in number picker?
support setWrapSelectorWheel in xml specification please
First of all, thank you for an awesome library!
It would be cool to add possibility to change an order of numbers to opposite, especially useful for vertical orientation in my case.
Thanks for this awesome widget! Could you add a function to set the min and max value from code also and not just xml?
Thanks!
I keep getting this error in Android Studio when previewing the layout. Do I need to declare a style in my theme for the numberPickerStyle attribute? The sample app does not appear to have anything like that. Thanks!
Failed to find style 'numberPickerStyle' in current theme
I have a situation, where setDisplayedValues
is called much later after view initialization, because data are coming from a remote service. In this case data showed by NumberPicker is totally wrong (they are overlapping and has wrong scroll behavior).
I could fix this behavior by replacing initializeSelectorWheelIndices
with initializeSelectorWheel
.
Patch:
reinitialize_wheel.txt
This conflicts with applications that don't use backup
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.