検索
[Android]RecyclerViewにアイテムが1つしか表示されない
- M.R

- 2020年8月9日
- 読了時間: 1分
更新日:2020年8月10日
現象
データベースからデータを読み取ってRecyclerViewで一覧表示をしたい。データベースには複数登録されているはずなのに、RecyclerViewには1つしか表示されない。前回と違い、RecyclerView.AdapterのgetItemCount()は適切に設定されている。
原因
個々のviewをxmlファイルで定義して、コンストラクタのnewViewメソッドでinflateしている。このinflate元のxmlファイルにおいて、1番外のlayoutのlayout_heightがmatch_parentになっていたこと。wrap_contentに変更したら無事すべてのアイテムが表示された。
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View inflate= LayoutInflater.from(context).inflate(R.layout.row, parent, false);
return inflate;
}row.xml
<LinearLayout 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" //ここ!
![[Android] TextViewを折り返したときに左右中央揃えにならない](https://static.wixstatic.com/media/90b712_795b2578740242d6b5309c31700a0f49~mv2.png/v1/fill/w_726,h_1438,al_c,q_90,enc_avif,quality_auto/90b712_795b2578740242d6b5309c31700a0f49~mv2.png)






コメント