How to configure TextView inside Spinner?

I have a Spinner with an ArrayAdapter that feeds values ​​into it. The layout for these views looks something like this:

        <TextView
           android:text="Household Income: "
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
           android:gravity="center_vertical" />

        <Spinner
           android:id="@+id/incomespinner"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:padding="2dip"  />

The problem is that the text is too long to represent, and the result is a very, very ugly counter. As seen in the screenshot:

alt text
(source: janusz on janusz.de )

I tried to pass the Id of my own TextView to the adapter, but every time a counter should be displayed, I get an exception that the specified Id is invalid:

04-26 17:38:39.695: ERROR/AndroidRuntime(4276): android.content.res.Resources$NotFoundException: Resource ID #0x7f09003a type #0x12 is not valid

Where should I define a TextView? In a separate XML file? With the surrounding group?

Would it help me a lot if I could see an example of adapter initialization and textview definition?

+5
3

, Spinner. , Spinner, .

, , . , .

, paddinbox Layout.

+3

getView .

View getView(int position, View  convertView, ViewGroup  parent) {
     TextView tv = null;
     if(covertView instanceof TextView) {
          tv = (TextView) convertView;
     } else {
          tv = new TextView(this);
          tv.setText("Awesome Text");
     }
     return tv;
}

, , ConvertView RelativeLayout LinearLayout.

+5

use / home / user / android-sdk-linux / tools /./ draw9patch (this is for Linux), on Windows go to tools in the android-sdk-windows directory and run draw9patch.

and use this image for example:

enter image description here

Attention to black lines in the image. (black lines are generated by draw9patch)

Image results are added to extension file 9, for example: img.9.png (IMG EXPANSIVE HORIZONTAL AND VERTICAL)

+1
source

All Articles