当我的所有数据都来自同一个 Retrofit 时,为什么使用 RecyclerView 而不是 ListView 会给我白屏结果?

Why does using RecyclerView instead of ListView give me white screen result when all of my data come from same Retrofit?

我想在 RecyclerView 中显示来自 GitHubApi 的数据,但我做不到。我可以在 ListView.I 中显示此数据 可以将 RecyclerView 与我自己的 List<> 集合数据一起使用。当我想将 RecyclerView 与 Retrofit 一起使用时,我的应用程序显示一个白屏而不是抛出错误。我无法解决这个问题。

        call.enqueue(new Callback<List<P006StrongClass>>() {
        @Override
        public void onResponse(Response<List<P006StrongClass>> response, Retrofit retrofit) {
            RecyclerView.Adapter adapter=new P006RecyclerViewAdapter(getApplicationContext(),response.body());
recyclerViewP006.setLayoutManager(new LinearLayoutManager(P006RetrofitRecyclerView.this, LinearLayoutManager.VERTICAL, false));
            recyclerViewP006.setAdapter(adapter);
        }
        @Override
        public void onFailure(Throwable throwable) {
        }
    }); 

这是我的 RecyclerView 适配器 class:

    public class P006RecyclerViewAdapter extends  RecyclerView.Adapter<P006RecyclerViewAdapter.MyViewHolder2> {
LayoutInflater layoutInflater;
List<P006StrongClass> p006StrongClassList;
MyViewHolder2 myViewHolder2;
public P006RecyclerViewAdapter(Context context,List<P006StrongClass> p006StrongClassList) {
    layoutInflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.p006StrongClassList=p006StrongClassList;
}

@Override
public MyViewHolder2 onCreateViewHolder(ViewGroup parent, int viewType) {
    View view= layoutInflater.inflate(R.layout.p006customrow, parent, false);
    myViewHolder2=new MyViewHolder2(view);
    return myViewHolder2;
}

@Override
public void onBindViewHolder(MyViewHolder2 holder, int position) {
    P006StrongClass p006StrongClassTek=p006StrongClassList.get(position);
    holder.textViewP006.setText(p006StrongClassTek.getId());
}

@Override
public int getItemCount() {
    return 0;
}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}

public static class MyViewHolder2 extends RecyclerView.ViewHolder{
    TextView textViewP006;
    public MyViewHolder2(View itemView) {
        super(itemView);
        textViewP006=(TextView)itemView.findViewById(R.id.textViewP006);
    }
}

您将返回 0 作为您的 itemCount,这意味着您的 RecyclerView

中没有任何项目
@Override
public int getItemCount() {
    return 0;
}

将其更改为

@Override
public int getItemCount() {
    return p006StrongClassList.size();
}