android - 从 JSON 显示两个不同的图像
问题描述
回收适配器
package com.example.maztec.celebstars.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.view.menu.MenuView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.maztec.celebstars.Pojodata.HeaderData;
import com.example.maztec.celebstars.Pojodata.ItemResponse2;
import com.example.maztec.celebstars.Pojodata.actorsrcs;
import com.example.maztec.celebstars.R;
import java.security.PublicKey;
import java.util.List;
public class ImageRecyclerAdapter extends RecyclerView.Adapter<ImageRecyclerAdapter.GetHeadersrcs> {
private Context context;
private List<HeaderData> Hsrcs;
public ImageRecyclerAdapter(Context context, List<HeaderData> hsrcs) {
this.context = context;
Hsrcs = hsrcs;
}
@NonNull
@Override
public ImageRecyclerAdapter.GetHeadersrcs onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(context);
View v=inflater.inflate(R.layout.single_header_design,parent,false);
return new GetHeadersrcs(v);
}
@Override
public void onBindViewHolder(@NonNull ImageRecyclerAdapter.GetHeadersrcs holder, int position) {
HeaderData hdata=Hsrcs.get(position);
final String id=hdata.getId();
Glide.with(context).load(hdata.getCat_image()).error(R.drawable.defaultceleb).into(holder.Headerimg1);
Glide.with(context).load(hdata.getCat_image()).error(R.drawable.defaultceleb).into(holder.Headerimg2);
}
@Override
public int getItemCount() {
return Hsrcs.size();
}
public class GetHeadersrcs extends RecyclerView.ViewHolder {
ImageView Headerimg1;
ImageView Headerimg2;
public GetHeadersrcs(View itemView) {
super(itemView);
Headerimg1=(ImageView) itemView.findViewById(R.id.circ1);
Headerimg2=(ImageView)itemView.findViewById(R.id.circ2);
}
}
public void setHeaderdata(List<HeaderData> headerdata){
this.Hsrcs=headerdata;
notifyDataSetChanged();
}
}
这是 JSON 响应
{
"data":[
{
"id":"1",
"cat_name":"Actor",
"cat_image":"http://mapi.trycatchtech.com/uploads/bollywood_wallpaper/1d96964ff5fee52c459b430399d0ad6b.jpg"
},
{
"id":"2",
"cat_name":"Actress",
"cat_image":"http://mapi.trycatchtech.com/uploads/bollywood_wallpaper/7b9d2f40a3f0fe3b6b37e66b5992be3a.jpg"
}
],
"last_update":"1525853619"
}
我想要的是演员的一种观点和女演员的一种观点,如果你能指导我哪里做错了。
解决方案
我认为您希望每行视图只有一张图像。所以改变:
HeaderData hdata=Hsrcs.get(position);
final String id=hdata.getId();
Glide.with(context).load(hdata.getCat_image()).error(R.drawable.defaultceleb).into(holder.Headerimg1);
Glide.with(context).load(hdata.getCat_image()).error(R.drawable.defaultceleb).into(holder.Headerimg2);
至:
HeaderData hdata=Hsrcs.get(position);
final String id=hdata.getId();
Glide.with(context).load(hdata.getCat_image()).error(R.drawable.defaultceleb).into(holder.Headerimg1);
您可以删除Headerimg2
,因为仅使用Headerimg1
就足够了。
推荐阅读
- vba - 替换 Word 文件中突出显示的文本
- python - HY090 - 无效的字符串或缓冲区长度 (0)
- ios - 如何在没有很多 xib 的情况下显示多个视图控制器
- php - AbstractDecoder.php 第 80 行中的 NotReadableException:无法从给定的 url 初始化 (https://example.net/img/picture.png?1549836294)
- php - 通过 AJAX 使用会话变量
- azure - 未找到类型或命名空间“BlobAttribute”
- android - 为什么可以从 Android 8.0 中的工作线程访问视图?
- haskell - Megaparsec ParsecT 的状态不回溯
- python - 如何使用正则表达式删除字符串中出现在单词两侧的各种标签?
- android - Android JDBC连接导致ctahttp异常