[英]How can I do an array for a listView with Strings located on parse.com?
[英]How can i make an array with strings located on parse.com?
嗨,大家好,我需要創建一個字符串數組才能在listView上顯示它們,這些字符串保存在我的parse.com數據庫中。
這是他們在parse.com上提供的從parse.com檢索對象的代碼
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
} else {
// something went wrong
}
}
});
這是包含listView的片段代碼,我希望在其中顯示字符串數組。
public class Grades extends ListFragment implements AdapterView.OnItemClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.grades_fragment,container,false);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.testArray, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//JUST FOR TESTING PURPOSES
Toast.makeText(getActivity(),"item" + position , Toast.LENGTH_SHORT).show();
}
}
我使用了由我創建的名為testArray的數組,該數組應該替換為我要使用從parse.com數據庫中獲取的字符串制作的數組。
所以我的問題是1)我應該在哪里找到parse.com建議使用的代碼? 2)如果我希望每當將字符串添加到數據庫時也將其添加到字符串數組,我該怎么辦?
非常感謝您的閱讀。
您可以將數組作為字符串推送到解析存儲中,例如:
"jump run skip play" // representation of new String[]{"jump", "run", "skip", "play"}
然后,您只需要使用標准的字符串方法在空格或您選擇用作分隔符的任何字符處分割字符串即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.