我花了 3 天多的时间从 Parse Cloud 获取图像文件。但它什么也没返回。我已经检查了后端,数据已添加到那里,但它没有返回图像。有天使可以帮我解决这个问题吗?
// Set up a customized query
ParseQueryAdapter.QueryFactory<AnywallPost> factory =
new ParseQueryAdapter.QueryFactory<AnywallPost>() {
public ParseQuery<AnywallPost> create() {
Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
ParseQuery<AnywallPost> query = AnywallPost.getQuery();
query.include("user");
query.orderByDescending("createdAt");
query.include("image");
query.whereWithinKilometers("location", geoPointFromLocation(myLoc), radius
* METERS_PER_FEET / METERS_PER_KILOMETER);
query.setLimit(MAX_POST_SEARCH_RESULTS);
return query;
}
};
// Set up the query adapter
postsQueryAdapter = new ParseQueryAdapter<AnywallPost>(this, factory) {
@Override
public View getItemView(AnywallPost post, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(), R.layout.anywall_post_item, null);
}
ParseFile photo = (ParseFile) post.get("image");
TextView contentView = (TextView) view.findViewById(R.id.content_view);
image = (ImageView) view.findViewById(R.id.picture_view);
imageloader.DisplayImage(post.getPhoto(),image);
TextView usernameView = (TextView) view.findViewById(R.id.username_view);
contentView.setText(post.getText());
usernameView.setText(post.getUser().getUsername());
post.setPhoto(photo.getUrl());
return view;
}
};
编辑版本:
// Set up a customized query
ParseQueryAdapter.QueryFactory<AnywallPost> factory =
new ParseQueryAdapter.QueryFactory<AnywallPost>() {
public ParseQuery<AnywallPost> create() {
Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
ParseQuery<AnywallPost> query = AnywallPost.getQuery();
query.include("user");
query.orderByDescending("createdAt");
query.whereWithinKilometers("location", geoPointFromLocation(myLoc), radius
* METERS_PER_FEET / METERS_PER_KILOMETER);
query.setLimit(MAX_POST_SEARCH_RESULTS);
return query;
}
};
// Set up the query adapter
postsQueryAdapter = new ParseQueryAdapter<AnywallPost>(this, factory) {
@Override
public View getItemView(AnywallPost post, View view, ViewGroup parent) {
if (view == null) {
view = View.inflate(getContext(), R.layout.anywall_post_item, null);
}
ParseFile photo = (ParseFile) post.get("image");
if (photo != null) {
photo.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// TODO Auto-generated method stub
if (data != null && e == null) {
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0,
data.length);
image.setImageBitmap(bitmap);
} else {
//ParseException e
}
}
});
} else {
//picture_not_available
}
TextView contentView = (TextView) view.findViewById(R.id.content_view);
image = (ImageView) view.findViewById(R.id.picture_view);
TextView usernameView = (TextView) view.findViewById(R.id.username_view);
contentView.setText(post.getText());
usernameView.setText(post.getUser().getUsername());
post.setPhoto(photo.getUrl());
return view;
}
};
最佳答案
您必须使用getDataInBackground
获取图像资源
if (photo != null) {
photo.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
// TODO Auto-generated method stub
if (data != null && e == null) {
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0,
data.length);
image.setImageBitmap(bitmap);
} else {
//ParseException e
}
}
});
} else {
//picture_not_available
}
关于java - 解析云不返回图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34564117/