0

I have implemented a custom spinner where no initial default selection is made. The code for NoDefaultSpinner is from this post https://stackoverflow.com/a/3427058/1257074

The problem is that the Prompt defined for this spinner in the xml layout file, is cuttoff if the Layout Width = wrap_content is less than the width of the Prompt text. See below.

NoDefaultSpinner cutoff

One solution is to just define a width in the xml file for the custom spinner, but unfortunately the spinner is generated dynamically in code.

Any ideas or suggestions please?

Community
  • 1
  • 1
Rynardt
  • 5,547
  • 7
  • 31
  • 43

2 Answers2

2

Just ended up dynamically changing the width:

RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) s1.getLayoutParams();
lp.width = 400;
s1.setLayoutParams(lp);
Rynardt
  • 5,547
  • 7
  • 31
  • 43
0

You could try overriding onMeasure(int,int) in the spinner with a special case "if nothing is selected" that size it correctly.

It's more or less what is done when inflating the xml.

Laucia
  • 222
  • 2
  • 11
  • Could you give an example of such an implementation? – Rynardt Aug 17 '12 at 13:10
  • You can find some on android website [here](http://developer.android.com/guide/topics/ui/custom-components.html) and with LabelView class (in the API sample code) – Laucia Aug 17 '12 at 14:06