亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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));



    }

您需要將適配器大小設置為您要檢索的大?。?/p>


 @Override

        public int getItemCount() {

               urlArray.size()

        }

或者


 @Override

    public int getItemCount() {

            return nameArray.sizes()

    }

我建議使用單個數組,或者可能是一個映射,以避免類似的問題。


查看完整回答
反對 回復 2023-06-21
  • 1 回答
  • 0 關注
  • 256 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號