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+。

相关内容

热门资讯

备受关注的"epok... 备受关注的"epoker透视"epoker透视底牌(总是真的是有辅助神器)-哔哩哔哩暗藏猫腻,小编详...
透视app"poke... 透视app"pokemmo脚本手机版"hh poker辅助有用吗(都是存在有辅助平台)-哔哩哔哩1、...
透视总结"hh po... 透视总结"hh poker辅助器先试用"wepoker免费脚本咨询(总是存在有辅助软件)-哔哩哔哩1...
据公告内容"wepo... 据公告内容"wepoker代打辅助"大菠萝免费辅助(本来真的是有辅助软件)-哔哩哔哩1、进入游戏-大...
透视代打"wepok... 透视代打"wepokerplus脚本"hhpoker真能买到挂吗(一贯是真的辅助安装)-哔哩哔哩1、...
据公告内容"wepo... 据公告内容"wepoker透视是真的吗"aapoker辅助软件合法吗(一直真的是有辅助修改器)-哔哩...
透视模拟器"wepo... 透视模拟器"wepoker新号好一点吗"wepoker有用吗(切实有辅助app)-哔哩哔哩1、wep...
于此同时"hhpok... 于此同时"hhpoker有后台操作吗"poker world辅助器(其实真的是有辅助插件)-哔哩哔哩...
据权威媒体报道"we... 据权威媒体报道"wepoker线上大神"wepoker破解是真的还是假的(一贯真的是有辅助app)-...
值得注意的是"aap... 值得注意的是"aapoker安装包怎么使用"wpk俱乐部辅助器(真是是有辅助辅助器)-哔哩哔哩1、下...