RecyclerViewでRoomのデータを一覧表示しようとしています。一覧にはなっているようですが、見切れており、全部表示させるようにしたいです。
kotlin
1class CustomAdapter(private val reportsList: List<Reports>): RecyclerView.Adapter<CustomAdapter.ViewHolder>() { 2 3 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 4 val view = LayoutInflater.from(parent.context).inflate(R.layout.list, parent, false) 5 return ViewHolder(view) 6 } 7 8 override fun onBindViewHolder(holder: CustomAdapter.ViewHolder, position: Int) { 9 val reports = reportsList[position] 10 11 holder.name.text = reports.title 12 holder.body.text = reports.impressions 13 } 14 15 override fun getItemCount(): Int = reportsList.size 16 17 class ViewHolder(view: View): RecyclerView.ViewHolder(view){ 18 19 val name: TextView 20 val body: TextView 21 22 init { 23 name = view.findViewById(R.id.name) 24 body = view.findViewById(R.id.body) 25 } 26 } 27}
xml
1<ScrollView 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:id="@+id/scrollView" 7 android:isScrollContainer="false"> 8 9 <LinearLayout 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:id="@+id/linearLayout"> 13 14 <LinearLayout 15 android:layout_width="0dp" 16 android:layout_height="wrap_content" 17 android:layout_weight="1" 18 android:orientation="vertical" 19 android:layout_marginStart="16dp"> 20 21 <TextView 22 android:layout_width="wrap_content" 23 android:layout_height="wrap_content" 24 android:id="@+id/name" 25 android:textStyle="bold"/> 26 <TextView 27 android:layout_width="wrap_content" 28 android:layout_height="wrap_content" 29 android:id="@+id/body"/> 30 <Button 31 android:layout_width="wrap_content" 32 android:layout_height="wrap_content" 33 android:text="戻る" 34 android:id="@+id/backBtn"/> 35 36 </LinearLayout> 37 38 39 </LinearLayout> 40 41</ScrollView>
Activity側のコードは以下です。
kotlin
1class SentMailListActivity : AppCompatActivity() { 2 3 private lateinit var binding : ActivitySentMailListBinding 4 private val viewModel: ReportsViewModel by viewModels() 5 lateinit var mAdapter: CustomAdapter 6 7 override fun onCreate(savedInstanceState: Bundle?) { 8 super.onCreate(savedInstanceState) 9 binding = ActivitySentMailListBinding.inflate(layoutInflater) 10 setContentView(binding.root) 11 12 // RecyclerViewの取得 13 //https://hirauchi-genta.com/kotlin-recyclerview/ 14 val recyclerView = binding.recyclerView 15 16 val dividerItemDecoration = DividerItemDecoration(this, LinearLayoutManager(this).orientation) 17 recyclerView.addItemDecoration(dividerItemDecoration) 18 19 // LayoutManagerの設定 20 recyclerView.layoutManager = LinearLayoutManager(this) 21 22 // CustomAdapterの生成と設定 23 mAdapter = CustomAdapter(viewModel.reportsData) 24 recyclerView.adapter = mAdapter 25 } 26}
xml
1<LinearLayout 2 xmlns:android="http://schemas.android.com/apk/res/android" 3 android:id="@+id/container" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent"> 6 7 <androidx.recyclerview.widget.RecyclerView 8 android:id="@+id/recycler_view" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content"/> 11</LinearLayout>
回答1件
あなたの回答
tips
プレビュー