I am trying to implement NumberPicker in my application. I want the view to be as show in
Dialogs Guide,which is
what i get when i implement the number picker
Also, i do not want to have text selected when i tap on selected item, from scroller
P.S. I tried searching around google and SO, but could not find correct answer for my question
I implemented solution provided here at SO.
Have already defined listener for value changed.
Tutorial/Guide is here, it just a quick overview of NumberPicker widget.
I want to implement view similar to
I think that depends on theme used
See NumberPicker at developer.android.com
Class Overview topic:
A widget that enables the user to select a number form a predefined range. There are two flavors of this widget and which one is presented to the user depends on the current theme.
If the current theme is derived from Theme the widget presents the current value as an editable input field with an increment button above and a decrement button below. Long pressing the buttons allows for a quick change of the current value. Tapping on the input field allows to type in a desired value.
If the current theme is derived from Theme_Holo or Theme_Holo_Light the widget presents the current value as an editable input field with a lesser value above and a greater value below. Tapping on the lesser or greater value selects it by animating the number axis up or down to make the chosen value current. Flinging up or down allows for multiple increments or decrements of the current value. Long pressing on the lesser and greater values also allows for a quick change of the current value. Tapping on the current value allows to type in a desired value.
Related
I have a registration form, when I select an especific option on input, a textField this form receive a value that cannot be changed, being able to only type with other values in this textField.
If you want to have a text field only the app can update (and the user can't type into), use a TextView.
If you want them to be able to type into it, but you want to be able to set a value and "lock" it so they can't edit it anymore, you can use an EditText and do enabled = false. That also greys out the field - if you don't want that, you can do inputType = EditorInfo.TYPE_NULL to prevent the keyboard from appearing.
If you want a fixed set of options that the user can choose from, you can use an AutoCompleteTextView or the Material Components equivalent
It seems that OnValueChangedListener is called when the value is changed programmatically by the app itself. Can I make it raised only when the user rotates the dial or know whether the event is from the app (code) or from the user?
You could have a field holding the pickers current value. If you want to set the current number of the picker from your code, change the field before updating the number picker. In the pickers listener, simply ignore events where the new number is already equal to the field. Otherwise handle the change and update the field.
Is there a way to remove the NumberPicker UP/DOWN arrows?
I googled but I wasn't able to find any method.. I have 2 devices one with android 4.2.2 and one with 4.0.3, in the first one the NumberPicker is scrollable and has no arrows while in the second one the NumberPicker isn't scrollable and has the up/down arrows
Quoted from the android documentation class overview:
In your older device you get this one.
If the current theme is derived from Theme the widget presents the current value as an editable input field with an increment button above and a decrement button below. Long pressing the buttons allows for a quick change of the current value. Tapping on the input field allows to type in a desired value.
Whereas what you desire is this flavour of the widget:
If the current theme is derived from Theme_Holo or Theme_Holo_Light the widget presents the current value as an editable input field with a lesser value above and a greater value below. Tapping on the lesser or greater value selects it by animating the number axis up or down to make the chosen value current. Flinging up or down allows for multiple increments or decrements of the current value. Long pressing on the lesser and greater values also allows for a quick change of the current value. Tapping on the current value allows to type in a desired value.
This would seem to be from a compatibility issue due to android version. Check what minimum version of android your Holo derived themes use in your app. It may be that the theme your older 4.* device is not accessing the same theme, but one that shares many similarities.
I think you should create your own number picker and inflate it.
You can follow this tutorial on inflating elements .
I have a timepicker showing the choice, but also shows the previous option above, and the next option below. I wish they would show these options are not, and it would show arrows such as in the image attached: http://www.subirimagenes.net/i/140728103732203512.png.
I have searched but have not found any solution.
From android/widget/NumberPicker.java:
If the current theme is derived from android.R.style#Theme the
widget presents the current value as an editable input field with an
increment button above and a decrement button below.
If the current theme is derived from android.R.style#Theme_Holo or
android.R.style#Theme_Holo_Light the widget presents the current value
as an editable input field with a lesser value above and a greater
value below.
According to this, before Holo the widget looked exactly how you wanted it. So try adding android:style="#android:style/Theme.Black" inside the <TimePicker /> in your layout xml file.
Help! in the first project the NumberPicker behaviour is that you can change the number by pressing + or - while in the second project the NumberPicker has 3 numbers and every time you roll it, the middle number changes to the correct one. Both projects use the same NumberPicker code!!
The behavior and appearance of NumberPicker depends on the theme that is in effect. From the docs for NumberPicker:
If the current theme is derived from Theme the widget presents the current value as an editable input field with an increment button above and a decrement button below. Long pressing the buttons allows for a quick change of the current value. Tapping on the input field allows to type in a desired value.
If the current theme is derived from Theme_Holo or Theme_Holo_Light the widget presents the current value as an editable input field with a lesser value above and a greater value below. Tapping on the lesser or greater value selects it by animating the number axis up or down to make the chosen value current. Flinging up or down allows for multiple increments or decrements of the current value. Long pressing on the lesser and greater values also allows for a quick change of the current value. Tapping on the current value allows to type in a desired value.
You evidently have different themes in effect for the NumberPicker in the two projects. More information is available in the Styles and Themes guide topic.