Show complete text value using numberpicker for strings in android

3.9k views Asked by At

I am using numberpicker widget for showing a spinner wheel for string values. I want to show the complete text value in an item window in numberpicker. how can i achieve it? I have multiple number picker widgets aligned horizontally. I can view some of the text of an item but not all of it. Please help!

2

There are 2 answers

2
adalpari On

You can just use the NumberPicker with an array of string

xml:

<NumberPicker
    android:id="@+id/np_string"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

code:

NumberPicker myNumberPicker = (NumberPicker) findViewById(R.id.np_string);

//Initializing a new string array with elements
final String[] values= {"one","two", "three", "four", "five"};

//Set min, max, wheel and populate.
myNumberPicker.setMinValue(0); 
myNumberPicker.setMaxValue(values.length-1);
myNumberPicker.setWrapSelectorWheel(true);
myNumberPicker.setDisplayedValues(values);
1
Meysam Keshvari On

strings.xml

<string-array name="numberPicker">
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
</string-array>

fill NumberPicker

binding.numberPicker.setMaxValue(getResources().getStringArray(R.array.numberPicker).length);
binding.numberPicker.setMinValue(0);        
binding.numberPicker.getResources().getStringArray(R.array.numberPicker);
binding.numberPicker.setWrapSelectorWheel(true);