像许多其他人一样,我在我的 android 应用程序中使用 Parse.com。当我在片段中使用 ParseQueryAdapter 来检索数据并将其传递给微调器时
java.lang.IllegalArgumentException: Spinner adapter view type count must be 1
和应用程序崩溃。
我已经搜索了修复程序,并且我知道这是 parse.com 而不是我必须解决的问题。但是,我真的想让我的应用看起来像 Material Design,如果我的应用 targetSdkVersion 19,状态栏总是黑色的。
这个问题有一个我不明白的答案,我不能直接在问题中提问,因为我没有特权。该社区的成员建议使用此代码扩展 parseadapter 并 @override getViewTypeCount。我是 Android 的新手,我不知道如何正确遵循该建议。如果你们能帮我解决这个问题,我将不胜感激。
更新:
我正在关注此答案中的代码,但出现错误提示MyParseAdapter does not have type parameters
。
你能解释一下我做错了什么吗?
谢谢
编辑:
public void addItemsOnSpinner (){
// Instantiate a QueryFactory to define the ParseQuery to be used for fetching items in this
// Adapter.
MyParseAdapter.QueryFactory<ParseObject> factory =
new MyParseAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Books");
//query.whereEqualTo("activated", true);
query.orderByAscending("title");
return query;
}
};
// Pass the factory into the ParseQueryAdapter's constructor.
ParseQueryAdapter<ParseObject> adapter = new MyParseAdapter<ParseObject>(getActivity(), factory);
adapter.setTextKey("title");
/* // Perhaps set a callback to be fired upon successful loading of a new set of ParseObjects.
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
public void onLoading() {
// Trigger any "loading" UI
}
public void onLoaded(List<ParseObject> objects, ParseException e) {
// Execute any post-loading logic, hide "loading" UI
}
});*/
spinnerBook.setPopupBackgroundResource(R.drawable.spinner_style);
spinnerBook.setAdapter(adapter);
spinnerBook.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Toast.makeText(parent.getContext(),
"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
// Log.d("test", spinnerBook.getSelectedItem().toString());
// Log.d("test2", parent.getItemAtPosition(pos).toString());
ParseObject item = (ParseObject) parent.getAdapter().getItem(pos);
objectID = item.getObjectId().toString();
//Log.d("test3",objectID);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Books");
query.getInBackground(objectID, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
bookTitle = object.getString("title");
txtBookAuthor.setText(object.getString("author"));
txtBookISBN.setText(object.getString("isbn"));
// category = object.getString("category");
} else {
// something went wrong
}
}
});
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}