Android 5.0中的Spinner适配器问题

时间:2015-05-17 03:52:05

标签: android android-5.0-lollipop android-spinner

我的应用与Android 5不兼容。

当我在任何其他版本中运行它时,它没有任何问题。

这是在Android 5中运行它时在logcat中出现的内容:

"\"

这里的问题在于logcat:

05-16 23:44:10.287    1969-1969/com.barakah.camel E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.barakah.camel, PID: 1969
java.lang.IllegalArgumentException: Spinner adapter view type count must be 1

regionSpinner和categorySpinner都是Spinner类型的对象 ...

 public void regionSpinnerSetup() {
    ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
        public ParseQuery create() {
            ParseQuery query = new ParseQuery("Region");
            return query;
        }
    };

    regionAdapter = new ParseQueryAdapter<ParseObject>(getActivity(),
            factory);
    regionAdapter.setTextKey("name");
    regionSpinner.setAdapter(regionAdapter);
    regionSpinner.setSelection(1);
    regionSpinner.setOnItemSelectedListener(new RegionSpinnerListener());
}

public void CategorySpinnerSetup() {
    ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
        public ParseQuery create() {
            ParseQuery query = new ParseQuery("Category");
            return query;
        }
    };

    categoryAdapter = new ParseQueryAdapter<ParseObject>(getActivity(),
            factory);
    categoryAdapter.setTextKey("name");
    categorySpinner.setAdapter(categoryAdapter);
    categorySpinner.setSelection(1);
    categorySpinner
            .setOnItemSelectedListener(new CategorySpinnerListener());
}

class RegionSpinnerListener implements Spinner.OnItemSelectedListener {
    @Override
    public void onItemSelected(AdapterView parent, View v, int position,
                               long id) {
        // TODO Auto-generated method stub

        ParseObject theSelectedObject = regionAdapter.getItem(position);
        Log.e("ABC", "Name is : " + theSelectedObject.getString("name") + " objectId is : " + theSelectedObject.getObjectId());
        regionobject = theSelectedObject;
    }

知道怎么解决吗?

2 个答案:

答案 0 :(得分:1)

我没有54b5ed4b967a4e3b96fe8a39的经验,但是通过阅读它,似乎你可以做这样的事情。

首先,创建一个扩展ParseQueryAdapter的自己的类,并覆盖ParseQueryAdapter

getViewTypeCount()

然后,只有代码中public class MyParseAdapter extends ParseQueryAdapter<ParseObject> { public MyParseAdapter(Context context, QueryFactory<ParseObject> clazz){ super(context, clazz); } @Override public int getViewTypeCount() { return 1; } } 的每个地方都将其替换为ParseQueryAdapter

MyParseAdapter

答案 1 :(得分:0)

你无法解决这个问题,因为在lollypop中这个问题是有关系的。所以这个应用程序可以在API 19或更低版本上运行。

如果您正在开发此应用程序,那么只有您可以对项目进行一些小改动。将您的adapter.getViewTypeCount()更改为1.这是唯一的解决方案。

您可以read for more reference