AndroidStudio中RecyclerView不显示问题。
创始人
2024-08-21 02:00:17
0
  1. 检查布局文件中是否有RecyclerView并确认其是否已正确配置。

例子:


  1. 检查RecyclerView是否已在适配器中进行了设置。例如:
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mCustomAdapter = new CustomAdapter(getActivity(), mDataSet);
mRecyclerView.setAdapter(mCustomAdapter);
  1. 确保适配器已正确实现必要的方法。例如:
public class CustomAdapter extends RecyclerView.Adapter {
    //This method will inflate the custom_layout and returning the view holder
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_layout, parent, false);
        return new ViewHolder(view);
    }

    //Binding the data into the holder
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.textView.setText(mDataSet.get(position));
    }

    //Getting the count
    @Override
    public int getItemCount() {
        return mDataSet.size();
    }

    //Creating a view holder class for holding the views
    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.text_view);
        }
    }
}
  1. 检查是否已正确引入支持库。在 build.gradle 文件中添加以下代码:
dependencies {
    compile 'com.android.support:recyclerview-v7:26.1.0'
}

此外,还需确认 compileSdkVersion 和 targetSdkVersion 是否已设置为 26+。

相关内容

热门资讯

第三分钟下载!微乐小程序免费黑... 第三分钟下载!微乐小程序免费黑科技,微乐小程序黑科技(开挂)总是真的有挂(2026)1、操作简单,无...
透视代打!微乐小程序免费黑科技... 透视代打!微乐小程序免费黑科技,微乐自建房脚本下载(透视)总是有挂(哔哩哔哩)1、任何微乐小程序免费...
第一分钟工具!微乐小程序黑科技... 第一分钟工具!微乐小程序黑科技,微乐河南家乡麻将辅助脚本(开挂)本来存在有挂(2026)1、每一步都...
总结辅助挂!微乐小程序黑科技,... 总结辅助挂!微乐小程序黑科技,微乐自建房运势高有什么表现(透视)本来是有挂(哔哩哔哩)微乐自建房运势...
第5分钟教程!微乐小程序黑科技... 第5分钟教程!微乐小程序黑科技,微乐游戏辅助脚本安装(开挂)其实存在有挂(2026)微乐小程序黑科技...
透视透视挂!微乐小程序黑科技,... 透视透视挂!微乐小程序黑科技,微信微乐自建房脚本免费下载(透视)果然是真的挂(哔哩哔哩)1、微信微乐...
3分钟脚本!微乐小程序黑科技,... 3分钟脚本!微乐小程序黑科技,微乐自建房脚本免费下载入口(开挂)都是存在有挂(2026);小薇(辅助...
7分钟下载!微乐小程序黑科技,... 7分钟下载!微乐小程序黑科技,万能透视辅助器免费版(开挂)一贯是真的挂(2026)1、微乐小程序黑科...
现有关情况通报如下!微乐小程序... 现有关情况通报如下!微乐小程序黑科技,微乐自建房怎么提高胜率(透视)一贯真的有挂(哔哩哔哩)1、微乐...
八分钟下载!微乐小程序免费黑科... 八分钟下载!微乐小程序免费黑科技,微信小程序 微乐陕西挖坑 外挂(开挂)原来是有挂(2026)一、微...