1

Hello I run in a trouble running the app in Android 5.1 emulator. I have a screen contains Spinner.This Spinner works fine on my phone running android 4.0+. I received an error like this:

java.lang.IllegalArgumentException: Spinner adapter view type count must be 1 at android.widget.Spinner.setAdapter(Spinner.java:439)

I have override a method like this:

@Override
public int getItemViewType(int position) {

    return 0;
}

@Override
public int getViewTypeCount() {

    if (hasTitle())
        return _models.length+1;
    else
        return _models.length;
}

I know the _models.length is greater 0 when I debug it. GetItemViewType not get hit during debugging.

The main problem is I have two screen that has two spinner. The first screen is working after using the above code but the second screen not that lucky.

Does any have an idea why the error appear even though my _models does have value in it.

Sorry, I may have missed read the error.. Must be 1... But why must be 1??

LittleFunny
  • 8,155
  • 15
  • 87
  • 198

1 Answers1

4

Simply make getViewTypeCount return 1.

This method allows you to inflate different layouts for different items. It, along with getViewType(), makes sure the correct type of View gets passed to getView() as convertView

Fletcher Johns
  • 1,236
  • 15
  • 20