此下图是按个人资料图片列出彼此的Instagram点赞者的仿真照片
我想在我的项目中实现此视图,以实现我拥有简单的JSONArray
和instagram赞者到feedsItems.get(position).getImage_versions2()
这个变量中
其中的数据是:
"facepile_top_likers": [{
"pk": "74778",
"username": "jewXXXXakher",
"full_name": "eeee",
"is_private": false,
"profile_pic_url": "https:\/\/scontent-frt3-1.cdninstagram.com\/vp\/c59859884e884a6\/5CEE31C6\/t51.2885-19\/s150x150\/30593311_581882262210963_4188149509433327616_n.jpg?_nc_ht=scontent-frt3-1.cdninstagram.com",
"profile_pic_id": "1765397207592984778",
"is_verified": false
}, {
"pk": "42441",
"username": "XXXX",
"full_name": "XXXku",
"is_private": false,
"profile_pic_url": "https:\/\/scontent-frt3-1.cdninstagram.com\/vp\/4c180\/5CFA6302\/t51.2885-19\/s150x150\/36938021_22245814328_n.jpg?_nc_ht=scontent-frt3-1.cdninstagram.com",
"profile_pic_id": "15985976441",
"is_verified": false
}, {
"pk": "3188",
"username": "RRRR",
"full_name": "RRRRR",
"is_private": true,
"profile_pic_url": "https:\/\/scontent-frt3-1.cdninstagram.com\/vp\/a1b8f4ec92e325775dc1096fc4db7ec9\/5CF67567\/t51.2885-19\/s150x150\/44711820_1802195912198400_n.jpg?_nc_ht=scontent-frt3-1.cdninstagram.com",
"profile_pic_id": "1924188",
"is_verified": false
}],
为此,我的代码是:
String post_image = "";
try {
JSONObject post_object = new JSONObject(feedsItems.get(position).getImage_versions2());
JSONArray post_array = post_object.getJSONArray("candidates");
post_image = post_array.getJSONObject(0).getString("url");
} catch (JSONException e) {
e.printStackTrace();
}
final String finalPost_image = post_image;
ImageHelper.loadImageWithCallback(
post_image, new Callback() {
@Override
public void onSuccess() {
ImageHelper.loadImage(finalPost_image, holder.square_image);
}
@Override
public void onError(Exception e) {
Picasso.get().load(R.drawable.image_not_found).into(holder.square_image);
}
}, holder.square_image);
结果:
ImageHelper
类:
public class ImageHelper {
public static void loadImageWithCallback(String url, Callback callback, ImageView postImageView) {
Picasso.get()
.load(url)
.error(R.drawable.cafe_alachiq_logo)
.into(postImageView, callback);
}
public static void loadImage(String url, ImageView postImageView) {
Picasso.get()
.load(url)
.error(R.drawable.cafe_alachiq_logo)
.into(postImageView);
}
}