복습 및 정리
ListView
사용자가 정의한 데이터 목록을 제한된 영역 안에서 목차의 형태로 유연하게 표현하기 위한 객체
ListView는 뷰객체(itemView)를 새로 생성하고 삭제하기를 반복 → 낭비가 심함 → 이를 해결하기 위해 RecyclerView 사용
뷰객체(급식판🍽) 갱신, 데이터(음식🍱) 갱신
Pros and Cons
Pros
- Easy to implement
- OnItemClickListener
Cons
- Bad performance in huge List of items
- Complicate way to use ViewHolder pattern (but can use it)
- Vertical list only
RecyclerView
이름에서도 알 수 있듯이 뷰객체를 재활용(Recycle)한다.
뷰객체(급식판🍽) 재활용, 데이터(음식🍱) 갱신
Pros and Cons
Pros
- Animations when adding, updating, and removing items
- Item decoration (borders, dividers)
- We can use It as a list or grid
- It let us use it together with DiffUti
- Faster performance, especially if you use RecyclerView.setHasFixedSize
- Mandatory ViewHolder pattern
Cons
- More code and sometimes unnecessary more difficult
- Not an easy way to add OnItemClickListener

Adapter
Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView.
DataList에 있는 data와 itemView를 연결, 바인딩하는 역할을 한다.
ViewHolder
A ViewHolder describes an item view and metadata about its place within the RecyclerView.
뷰객체를 홀딩해주는, 즉 뷰객체들이 날라가지 않도록 담고 있는 그릇
LayoutManager
A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.
아이템들의 배열 형태를 결정한다. ex) 수직, 수평, 격자 형태
DataList
RecyclerView에 들어갈 데이터 목록
RecyclerView에서 Click Listener의 사용
onBindViewHolder가 매개변수로 position값을 갖고 있기 때문에 보통 onBindViewHolder에서 click 이벤트를 작성하는 것이 좋다.
adapter의 외부 activity나 fragment에서 click event를 처리하기 위해 click listener 역할을 하는 interface를 만들어줘야 한다.
Else
cardView
Implement the Material Design card pattern with round corners and drop shadows.
모서리가 둥근 view를 구현할 수 있다.
intent vs bundle
Activity와 Fragment간 데이터를 전달할 때 우리는 흔히 Intent와 Bundle을 사용해서 데이터를 전달한다.
intent : 저장이 아닌 전달하는 수단으로의 객체
bundle : 상태/값 등을 저장하기 위한 객체, map 형태
참조
https://dev.to/jbc7ag/recyclerview-or-listview-pros-cons-and-examples-with-kotlin-2nb2
https://ardor-dev.tistory.com/76
https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter
https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager
https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder
'대외활동 > UMC' 카테고리의 다른 글
| [UMC 2기] Android 파트 8주차 정리 (0) | 2022.05.24 |
|---|---|
| [UMC 2기] Android 파트 7주차 정리 (0) | 2022.05.19 |
| [UMC 2기] Android 파트 5주차 정리 (0) | 2022.05.04 |
| [UMC 2기] Android 파트 4주차 정리 (0) | 2022.04.29 |
| [UMC 2기] Android 파트 3주차 정리 (0) | 2022.04.26 |