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

相关内容

热门资讯

玩家必备教程!雀神小程序辅助购... 玩家必备教程!雀神小程序辅助购买是真是假(辅助挂)太坑了原来是真的有挂(有挂规律)-哔哩哔哩;广东雀...
一分钟秒懂!新版边锋掼蛋辅助器... WePoke高级策略深度解析‌;一分钟秒懂!新版边锋掼蛋辅助器,微扑克辅助网,详细有挂(有挂攻略)-...
透明教学(德扑之星ai)外挂透... 透明教学(德扑之星ai)外挂透明挂辅助器(德州)软件透明挂(2022已更新)(哔哩哔哩);玩家在德扑...
实操分享!边锋老友棋牌是有挂(... 实操分享!边锋老友棋牌是有挂(wEpOke),太坑了其实是真的有挂(有挂技巧)-哔哩哔哩1、不需要A...
重磅来袭!边锋老友棋牌能装挂,... 重磅来袭!边锋老友棋牌能装挂,pokertime挂百度知道,详细有挂(有挂规律)-哔哩哔哩1、让任何...
玩家必看科普!雀神广东麻将专用... 玩家必看科普!雀神广东麻将专用神器(透视)太坑了原来真的有挂(有挂了解)-哔哩哔哩;雀神广东麻将专用...
重大通报(Wepoke规律)外... 重大通报(Wepoke规律)外挂透明挂辅助软件(ai代打)发牌机制(2021已更新)(哔哩哔哩)1、...
透明软件!川麻圈辅助工具(WE... 透明软件!川麻圈辅助工具(WEPoke),太坑了原来真的有挂(有挂教学)-哔哩哔哩,支持语音通讯、好...
6分钟了解!鄱阳翻精扑克助赢神... 6分钟了解!鄱阳翻精扑克助赢神器购买,wepoker透视脚本下载,详细有挂(有挂详情)-哔哩哔哩;精...
重要通知!雀神广东麻将神器软件... 大家肯定在之前雀神广东麻将神器软件要root或者雀神广东麻将神器软件要root中玩过重要通知!雀神广...