Android RecyclerView item 선택하기
사용 버전: Android Studio 4.0
사용 언어: Kotlin 1.3.72
안드로이드 RecyclerView item 선택하기를 알아보겠습니다.
RecyclerView 안에 있는 아이템을 선택하여 새로운 화면으로 이동하는 것을
해보겠습니다.
Recycler를 사용합니다.
누르면 아래 페이지로 이동하게 만들 겁니다.

Navigation에 추가합니다.

Rebuild 합니다.
Adapter 파일에 아래를 추가합니다.

그리고 bind에 clickListener를 적습니다.

MorningAdapter에 clickListener를 추가하고, holder.bind에 clickListener를
추가합니다.

RecyclerView에 사용되는 layout xml 파일로 갑니다.
위에서 만든 clickListner를 추가합니다.

그리고 RecyclerView의 부모 Layout을 클릭 가능하게 onClick을 적습니다.

Fragment로 가서 Adapter를 바꿉니다.

결과입니다.

선택된 ID가 표시되고, DetailsFragment로 이동되었습니다.

끝.
카테고리: Android
댓글
댓글 쓰기
궁금한 점은 댓글 달아주세요.
Comment if you have any questions.