【发布时间】:2012-11-26 21:57:01
【问题描述】:
我对 android 非常陌生,对 Parse 非常陌生。我创建了一个类 StudentInformation,其中包括姓名、地址、电话等列。 我想创建一个列表视图,其中包含添加到班级的所有学生的姓名。
我该怎么做?我已经到了可以吐出所有条目的 objectID 的程度,但不知道如何提取名称并将其仅添加到 ListView。
这是一个sn-p的代码:
//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 的地方。
我们将一如既往地为您提供任何帮助。
应该提到(可能),不会抛出任何错误,在 toast 消失后列表视图永远不会被填充。
不知道这是否会对任何人有所帮助,但我从下面的两个帖子中吸取了一些信息,并想出了这个:
//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();
}
}
});
【问题讨论】:
标签: java android parse-platform