我是Android和解析的新手。我已经将一些图片上传到我的解析后端,并希望在我的应用中显示它们。
我知道图像在那里并且可以访问,因为当我禁用我的过滤器时,我得到了我想要的结果。我已经查看了我的代码,所有内容都检查出来,但没有结果。我有什么可以忽略的?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_feed);
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
Intent intent = getIntent();
final String activeUserName = intent.getStringExtra("username");
setTitle(activeUserName + "'s Feed");
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Image");
//query.whereEqualTo("username", activeUserName);
//query.orderByDescending("createdAt");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
for (ParseObject object : objects) {
ParseFile file = (ParseFile) object.get("image");
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null && data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
ImageView imageView = new ImageView(getApplicationContext());
imageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
imageView.setImageBitmap(bitmap);
linearLayout.addView(imageView);
}
}
});
}
} else {
Toast.makeText(UserFeedActivity.this, activeUserName + " " + getString(R.string.feed_no_images), Toast.LENGTH_SHORT).show();
}
}
}
}
); }