java – 尝试使用Parse中的对象在Android中填充ListView
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 尝试使用Parse中的对象在Android中填充ListView,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2472字,纯文字阅读大概需要4分钟。
内容图文
![java – 尝试使用Parse中的对象在Android中填充ListView](/upload/InfoBanner/zyjiaocheng/731/c1b2020859bd412aa68b80c626e38bd7.jpg)
我对android非常了不起,对Parse来说非常新.我创建了一个类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);
}
我已经离开了toast,我在public void done ….方法中删除了objectIDs.
任何帮助将一如既往地非常感谢.
应该提到(可能),没有抛出任何错误,在toast消失后listview只是永远不会被填充.
不知道这是否会对任何人有所帮助,但我从下面的两个帖子中得到了一点,并想出了这个:
//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();
}
}
});
解决方法:
你有2个问题:
1)listAdapter包含列表中显示的数据.您需要在运行查询之前创建此查询并获取查询以直接将值添加到listAdapter.完成填充后,您需要调用listAdapter.notifyDataSetChanged(),以便使用新数据重新绘制列表.
2)将值添加到studentList的功能是添加“name”.toString().您可能想要调用studentList.add(objects.get(i));
内容总结
以上是互联网集市为您收集整理的java – 尝试使用Parse中的对象在Android中填充ListView全部内容,希望文章能够帮你解决java – 尝试使用Parse中的对象在Android中填充ListView所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。