0

Bit of a strange issue here,

The spinner items show perfectly and when an item is selected, that item is then shown on the spinner. All is well except for when I select on option - KILOGRAM (see below), it is programatically selected but the "kg" symbol that should be display is not, there is just an empty spinner

I have 3 separate Enum values

public enum Unit
{
    // Different unit names and symbols
    PERCENTAGE ("%", 0),
    KILOGRAMS ("kg", 1),
    POUNDS ("lb", 2);

    private String symbol;
    private int position;

    Unit(String symbol, int position)
    {
        this.symbol = symbol;
        this.position = position;
    }

    // Get symbol
    public String getSymbol()
    {
        return symbol;
    }
}

They populate the spinner via the following code.

    // Set Unit spinners
    units = new ArrayList<String>();

    for (Unit unit : Unit.values())
    {
        units.add(unit.getSymbol());
    }

    ArrayAdapter <String> unitAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, units);

    sSuccessUnit.setAdapter(unitAdapter);

And that's about it, it seems to be very strange. I tried adding another KILOGRAMS enum and therefore had two but I had the same problem for both. I tried adding another POUNDS enum and just like before that worked perfectly. I also tried to add OUNCES ("oz") and that didn't work either..

Any ideas?

EDIT: To clear that question up a little bit.. Everything that is meant to be shown ("%","kg","lb") is shown. When I select "%" and "lb", that is what I see selected in the spinner, when I select "kg", the spinner shows " ", an empty selection

mgibson
  • 6,103
  • 4
  • 34
  • 49
  • items are shown and options are not shown? what do you mean? what is an item and what is an option? – koem Jun 23 '13 at 19:31
  • Everything that is meant to be shown ("%","kg","lb") is shown, when I select "%" and "lb", that is what I see selected in the spinner, when I select "kg", the spinner shows " ", an empty selection – mgibson Jun 23 '13 at 19:37

1 Answers1

1

The problem was that the spinner wasn't wide enough.

"kg" was the widest name I was trying to display and by simply increasing the width everything was solved.

mgibson
  • 6,103
  • 4
  • 34
  • 49
  • its recommended not to use enum http://stackoverflow.com/questions/4822877/why-doesnt-android-use-more-enums – MDMalik Jun 23 '13 at 20:27
  • Read that question more and follow the links and you will see that is no longer the case – mgibson Jun 23 '13 at 21:25