你好我有此JSON數據a link我如何知道從recyclerview中選擇的任何圖像?
和我解析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);
這個代碼是爲onBindViewHolder 和我嘗試添加getAdapterPosition());給視圖持有者其connot reslove! –