为了账号安全,请及时绑定邮箱和手机立即绑定

RecyclerView 在向下滚动时崩溃(IndexOutOfBoundsException:)

RecyclerView 在向下滚动时崩溃(IndexOutOfBoundsException:)

慕雪6442864 2023-06-21 14:49:20
我从 json 解析数据并将其传递给包含两个 Arraylist 的 ArrayList,然后将它们传递给 RecyclerView,RecyclerView 显示数据,但 1 项占用整个页面,当我向下滚动时,我可以看到第二项,然后它崩溃了我尝试了很多人的建议,让父视图或回收商的视图 layout_heigt="wrap_content" 它甚至不会打开页面这里是回收商的视图 xml(activity_resultsdwldview) 和 row.xml 其中包含每行的 cardview 设计如果这没有组织或不清楚,请原谅我,我真的时间很短,而且是一个没有太多经验的初级 android 开发人员activity_resultsdwldview.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="wrap_content"    tools:context=".Resultsdwldview">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        andoid:orientation="vertical">        <android.support.v7.widget.RecyclerView            android:id="@+id/recyvlerView"            android:layout_width="match_parent"            android:layout_height="match_parent" />    </LinearLayout></RelativeLayout>行.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical">    <android.support.v7.widget.CardView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginStart="12dp"        android:layout_marginTop="12dp"        android:layout_marginEnd="12dp"        android:layout_marginBottom="12dp">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical">            <TextView                android:id="@+id/nameArray"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:textSize="20dp" />        </LinearLayout>    </android.support.v7.widget.CardView></LinearLayout>
查看完整描述

1 回答

?
素胚勾勒不出你

TA贡献1827条经验 获得超9个赞

您的适配器的大小由以下各项设置:


 @Override

    public int getItemCount() {

            return Tests.size();

    }

并且您尝试从以下位置获取物品:


 @Override

    public void onBindViewHolder(@NonNull MainAdapter.ViewHolder holder, int i) {


        holder.URLName.setText( urlArray.get(i));

        holder.mFullname.setText( nameArray.get(i));



    }

您需要将适配器大小设置为您要检索的大小:


 @Override

        public int getItemCount() {

               urlArray.size()

        }

或者


 @Override

    public int getItemCount() {

            return nameArray.sizes()

    }

我建议使用单个数组,或者可能是一个映射,以避免类似的问题。


查看完整回答
反对 回复 2023-06-21
  • 1 回答
  • 0 关注
  • 133 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信