私はアンドロイドにはかなり慣れていませんが、パースには非常に慣れていません。名前、住所、電話番号などの列を含むクラス StudentInformation を作成しました。クラスに追加されたすべての生徒の名前を含むリストビューを作成したいと考えています。
どうすればいいですか?すべてのエントリの objectID をトーストできるところまで来ましたが、名前だけを抽出して ListView に追加する方法がわかりません。
コードのスニペットを次に示します。
//Set up the listview
studentListView = (ListView)findViewById(R.id.listViewStudents);
//Create and populate an ArrayList of objects from parse
ParseQuery query = new ParseQuery("StudentInformation");
final ArrayList<Object> studentList = new ArrayList<Object>();
query.findInBackground(new FindCallback() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(), objects.toString(), Toast.LENGTH_LONG).show();
for(int i = 0;i < objects.size(); i++){
objects.get(i);
studentList.add("name".toString());
}
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}
}
});
//studentList.addAll(Arrays.asList(students));
listAdapter = new ArrayAdapter<Object>(this,android.R.layout.simple_list_item_1,studentList);
studentListView.setAdapter(listAdapter);
}
public void done.... メソッドで objectID を toatst する場所にトーストを残しました。
いつものように、どんな助けでも大歓迎です。
(おそらく)言及する必要がありますが、エラーはスローされません。トーストが消えた後、リストビューにデータが入力されることはありません。
これが誰かに役立つかどうかはわかりませんが、以下の両方の投稿から少し抜粋して、これを思いつきました:
//Set up the listview
studentList = new ArrayList<String>();
//Create and populate an ArrayList of objects from parse
listAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
studentListView = (ListView)findViewById(R.id.listViewStudents);
studentListView.setAdapter(listAdapter);
final ParseQuery query = new ParseQuery("StudentInformation");
query.findInBackground(new FindCallback() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
//Toast.makeText(getApplicationContext(), objects.toString(), Toast.LENGTH_LONG).show();
for (int i = 0; i < objects.size(); i++) {
Object object = objects.get(i);
String name = ((ParseObject) object).getString("name").toString();
listAdapter.add(name);
}
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
}
}
});