Search code examples
androidnumberpicker

How to make NumberPicker text area wider?


I'm using NumberPicker with String values displayed. Here is the example:

odaberiRazinu.setVisibility(View.VISIBLE);
odaberiRazinu.setMinValue(0);
odaberiRazinu.setMaxValue(3);

odaberiRazinu.setDisplayedValues( new String[] { "FirstAnswer", "SecondAnswer", "ThirdAnswer", "FourthAnswer"} );

I have problems, because from FirstAnswer, only it's only visible "stAnsw" (something like that). When I move it, then it gets wider sometimes, but it's not working well.

Is there a way to make a display area wider or is there a better way to make NumberPicker-like mechanism for Strings?

EDIT (this is XML layout):

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

Solution

  • This code works for me. The NumberPicker is as wide as the longest item text. Maybe you have to choose a different size for the parent layout.

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <NumberPicker
            android:id="@+id/section_numberPicker"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    
    </FrameLayout>
    

    enter image description here

    Also you can set a static widht android:layout_width="300dp" but then it will truncate the text ifi it is longer.