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、不需要AI权限,帮助...
第4分钟下载!微乐小程序黑科技... 第4分钟下载!微乐小程序黑科技,微乐自建房辅助软件下载(开挂)好像真的是有挂(2026)1、许多玩家...
在玩家背景下!微乐小程序黑科技... 在玩家背景下!微乐小程序黑科技,微乐小程序辅助器出租(透视)都是是真的挂(哔哩哔哩)暗藏猫腻,小编详...
一分钟开挂!微乐小程序黑科技,... 一分钟开挂!微乐小程序黑科技,微乐科技软件下载(开挂)竟然是有挂(2026)1、微乐小程序黑科技免费...
推出新举措!微乐小程序免费黑科... 推出新举措!微乐小程序免费黑科技,微信小程序怎么开挂(透视)竟然真的是有挂(哔哩哔哩)1、每一步都需...
4分钟透视!微乐小程序免费黑科... 4分钟透视!微乐小程序免费黑科技,微乐小程序怎么挂脚本(开挂)好像是真的挂(2026)1)微乐小程序...
透视中牌率!微乐小程序黑科技,... 透视中牌率!微乐小程序黑科技,微乐自建房辅助工具官网(透视)好像是有挂(哔哩哔哩);1、金币登录送、...
第7分钟神器!微乐小程序免费黑... 第7分钟神器!微乐小程序免费黑科技,微信微乐辅助免费(开挂)一贯有挂(2026)1、操作简单,无需微...
2026版教程!微乐小程序免费... 2026版教程!微乐小程序免费黑科技,微乐自建房道具有用吗(透视)其实真的有挂(哔哩哔哩)1.微乐自...