【发布时间】:2016-09-16 03:58:56
【问题描述】:
你好我有这个json数据a link
我将jsonArray解析成
这是一段json,
"im:image":[
{
"label":"http://is1.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/53x53bb-85.png",
"attributes":{
"height":"53"
}
},
{
"label":"http://is5.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/75x75bb-85.png",
"attributes":{
"height":"75"
}
},
{
"label":"http://is3.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/100x100bb-85.png",
"attributes":{
"height":"100"
}
}
但是当我点击这里的任何图片时,我只得到了这张图片!
我该如何解决这个问题,当我点击“snapchat”时,我得到了快照的图像?
这是解析json的方法
public void JsonAppShowData() {
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( jsonUrl, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) { try {
JSONArray jsonArray = response.getJSONObject(feedKey).getJSONArray(entryKey);
AppShowModule appShowModule = new AppShowModule();
int x = appShowModule.getId();
for (int i = 0; i<jsonArray.length();i++)
{
JSONArray imageArray = response.getJSONObject(feedKey).getJSONArray(entryKey).getJSONObject(i).getJSONArray(imageKey);
for (int j = 0; j < imageArray.length(); j++) {
String image = imageArray.getJSONObject(j).getString(labelKey).toString();
imageUrls.add(image);
appShowModule.setAllimage(imageUrls);
appShowModules.add(appShowModule);
}}
imageRecyclerViewadapter = new ImageListAdapter(appShowModules, getContext(), imageUrls);
AppRecyclerView.setAdapter(imageRecyclerViewadapter);
} catch (JSONException e) {
e.printStackTrace();
}}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e( "LOG", error.toString() );
}
} );
这是图片列表加载器
public class ImageListAdapter extends RecyclerView.Adapter<ImageListAdapter.ViewHolder> {
List<AppShowModule> appShowModules;
List<String> imageUrl;
AppShowModule appShowModule;
String x;
Context context;
public ImageListAdapter(List<AppShowModule> appShowModules, Context context ,List<String>imageUrls
){
super();
this.imageUrl =imageUrls;
this.appShowModules = appShowModules;
this.context = context;}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.imagelayout, parent,false );
ViewHolder viewHolder = new ViewHolder( v );
return viewHolder;}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
AppShowModule appShowModule = appShowModules.get(position);
x = appShowModule.getAllimage().get(position);
Picasso.with(context).load(x).into(holder.appImage);
}
public int getItemCount() {
return imageUrl.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ImageView appImage;
public ViewHolder(View itemView) {
super(itemView);
appImage = (ImageView) itemView.findViewById(R.id.appImage);
appImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent= new Intent(context, ImageShow.class);
intent.putExtra("image", x);
context.startActivity(intent);
}});
}
}
}
这是点击时将显示的活动
appImage=(ImageView)findViewById(R.id.appImage);
Picasso.with(context).load(x).into(appImage);
【问题讨论】: