Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NumberPicker Widget with Strings

Tags:

android

Is there a way to use the Android NumberPicker widget for choosing strings instead of integers?

like image 209
timoschloesser Avatar asked Nov 22 '11 12:11

timoschloesser


People also ask

How do I change the number on my picker style?

Unfortunately, you can't style it. The styles and styling attributes for NumberPicker are not present in the public API, therefore you can't set them and change the default look. You can only select between light and dark theme. As a solution I would suggest to use android-numberpicker library instead.

How do you make a number picker horizontal?

Implementing Horizontal picker in Android using RecyclerView and LinearLayoutManager with kotlin. Its a number picker which has the below functionality. >middle item will be selected, clicking on item will also be selected.


2 Answers

NumberPicker picker = new NumberPicker(this); picker.setMinValue(0); picker.setMaxValue(2); picker.setDisplayedValues( new String[] { "Belgium", "France", "United Kingdom" } ); 
like image 116
nan Avatar answered Sep 19 '22 10:09

nan


NumberPicker numberPicker = new NumberPicker(this); String[] arrayString= new String[]{"hakuna","matata","timon","and","pumba"}; numberPicker.setMinValue(0); numberPicker.setMaxValue(arrayString.length-1);  numberPicker.setFormatter(new NumberPicker.Formatter() {   @Override   public String format(int value) {     // TODO Auto-generated method stub     return arrayString[value];   } }); 

hope that helps!

like image 21
harshitpthk Avatar answered Sep 21 '22 10:09

harshitpthk