我在Parse.com下载Photo时遇到问题。 在Parse我有6张照片,但在我将它下载到我的照片数组列表后,我显示photos.size()= 12.我不明白为什么它是照片的两倍?我该如何解决?
try {
ParseQuery <ParseObject> query = new ParseQuery <> ("photo");
query.orderByAscending("ImageName");
List <ParseObject> listA = query.find();
for (final ParseObject mPhoto: listA) {
final Photo newPhoto = new Photo();
final ParseFile photo = (ParseFile) mPhoto.get("imageFile");
photo.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, com.parse.ParseException e) {
if (e == null) {
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
newPhoto.setBitmap(bmp);
newPhoto.setTrade_id((String) mPhoto.get("trade_id"));
photos.add(newPhoto);
} else {
Log.e("test", "Problem load image the data.");
}
}
});
}
} catch (com.parse.ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
try {
ParseQuery <ParseObject> query = new ParseQuery < > ("trade");
query.addDescendingOrder("updatedAt");
List < ParseObject > listA = query.find();
for (ParseObject mTrade: listA) {
Trade newTrade = new Trade();
newTrade.setUpdateCount((int) mTrade.get("UpCount"));
newTrade.setmUser((String) mTrade.get("user"));
newTrade.setmKind((String) mTrade.get("kind"));
newTrade.setmAddress((String) mTrade.get("address"));
newTrade.setmCost((String) mTrade.get("cost"));
newTrade.setmDetail((String) mTrade.get("detail"));
newTrade.setmID((String) mTrade.get("trade_id"));
newTrade.setmPhone((String) mTrade.get("phone"));
newTrade.setmTopic((String) mTrade.get("topic"));
for (int i = 0 ; i < photos.size() ;i++){
if (newTrade.getmID().equals(photos.get(i).getTrade_id())){
newTrade.addBitmap(photos.get(i).getBitmap());
}
if (newTrade.getBitmaps().size()==4){
i=photos.size();
}
}
trades.add(newTrade);
}
} catch (com.parse.ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}