我创建了一个基本查询,它将从Parse云中提取名称,用户名和图像并将其加载到ListView中。目前云中有3个测试用户。当我执行查询时,信息被拉出并且可以通过Logcat看到。但是当尝试使用我的自定义基本适配器将其加载到列表视图中时,根本不会显示任何内容。它只返回listview应该是的空白区域。
我已经将问题分解为我认为导致问题的方法:
public void findUserFriends() {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereNotEqualTo("username", "~");
query.findInBackground(new FindCallback<ParseUser>() {
public void done(final List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
ArrayList myList = new ArrayList();
for (int i = 0; i < objects.size(); i++) {
FriendListData fld = new FriendListData();
fld.setUsername(objects.get(i).getUsername());
fld.setFullname(objects.get(i).getString("name"));
final ParseFile picture = objects.get(i).getParseFile("profilepicture");
if (picture == null) {
Toast.makeText(getApplicationContext(), "No File Found", Toast.LENGTH_LONG).show();
return;
}
picture.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null) {
if (data.length == 0) {
// data found, but nothing to extract. bad image or upload?
Toast.makeText(getApplicationContext(), "Image is bad. Please Try Again Later", Toast.LENGTH_LONG).show();
return;
}
// SUCCESS
// convert data and display in an imageview
FriendListData fld = new FriendListData();
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
fld.setProfilePicture(bmp);
} else {
Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_LONG).show();
}
}
});
myList.add(fld);
}
} else {
Toast.makeText(getApplicationContext(), "No Users Found.", Toast.LENGTH_LONG).show();
}
}
});
}
然后我在onCreate
方法中执行此操作:
lvDetail = getListView();
findUserFriends();
lvDetail.setAdapter(new FriendBaseAdapter(context, myList));
如上所述,所有需要的数据都是从云中提取的,当我使用我的logcat时可以看到。它们只是不加载到ListView中。我不确定我做错了什么。
赞赏所有帮助。
答案 0 :(得分:1)
似乎您在异步加载完成之前设置了适配器 - 尝试在lvDetail.setAdapter(new FriendBaseAdapter(context, myList));
之后的回调中移动此行myList.add(fld);