Spinner Error “Spinner adapter view type count mus

2019-01-28 10:35发布

问题:

I am using Parse.com in my application when I use ParseQueryAdapter in fragment to retrieve data and pass to a spinner an error as

java.lang.IllegalArgumentException: Spinner adapter view type count must be 1

and application stops. However if I try ArrayAdapter it works. What could be the problem?

ParseQueryAdapter Code:

ParseQueryAdapter.QueryFactory<ParseObject> spnQuery=
            new ParseQueryAdapter.QueryFactory<ParseObject>() {
                public ParseQuery create() {
                    ParseQuery query = new ParseQuery(tableName);
                    return query;
                }
            };
    ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(getActivity().getApplicationContext(), spnQuery);
    adapter.setTextKey(columnName);
    spnLecture.setAdapter(adapter);

回答1:

ParseQueryAdapter might be using SpinnerAdapter underneath.

One way to solve this issue is to lower your targetSdkVersion. This error is being reported for targetSdkVersion of 21.

Please see here : https://code.google.com/p/android/issues/detail?id=79011

A long term solution is to fix the implementation of the adapter, which is not possible for your case until Parse team decides to fix it.

I had the same issue with SpinnerAdapter and got it working without peripheral damage using targetSdkVersion 19. Hope it helps!



回答2:

I have solved the same problem just now, and you have two possible solutions:

a. Down the targetSdkVersion to 19

b. (My prefered) Extend your parseadapter and @override the getViewTypeCount with this code:

@Override
public int getViewTypeCount() {
     return 1;
}

This works for me :)