Reputation: 71
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!
Upvotes: 2
Views: 4053
Reputation: 1201
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);
Upvotes: 0
Reputation: 3121
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);
Upvotes: 2