我将 ParseFile 加载到数组列表照片中。 但现在我想在 ImageView 中显示它?
ArrayList<Photo> photos = new ArrayList<>();
try {
ParseQuery<ParseObject> query = new ParseQuery<>("photo");
query.setLimit(2000);
List<ParseObject> listA = query.find();
for (ParseObject mPhoto : listA) {
Photo newPhoto = new Photo();
newPhoto.setImage((ParseFile) mPhoto.get("imageFile"));
newPhoto.setTrade_id((String) mPhoto.get("trade_id"));
photos.add(newPhoto);
}
} catch (com.parse.ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
我该怎么做?
最佳答案
试试这个代码。这将向您展示如何为 1 个 ParseFile
显示 1 个图像
。如果您想显示arraylist
中的所有图像,您应该将Bitmap对象
保存到arraylist
而不是ParseFile对象
。
ParseFile fileObject = (ParseFile) object
.get("imageFile");
fileObject
.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
// Decode the Byte[] into
// Bitmap
Bitmap bmp = BitmapFactory
.decodeByteArray(
data, 0,
data.length);
// initialize
ImageView image = (ImageView) findViewById(R.id.image);
// Set the Bitmap into the
// ImageView
image.setImageBitmap(bmp);
} else {
Log.d("test",
"Problem load image the data.");
}
}
});
另一种方法是您需要获取图像的 url
String imageUrl = parseFileObject.getUrl();
然后使用 Picasso或UniversalImageLoader用于加载图像
注意:您应该使用 AsyncTask使用 Parse 提高性能和同步
希望这有帮助
关于android - 从解析到 ImageView 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901767/