我從 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()
}
我建議使用單個數組,或者可能是一個映射,以避免類似的問題。
添加回答
舉報
0/150
提交
取消