[Android/Layout]리사이클러뷰 내 Swipe 기능으로 리스트 새로고침
2021. 5. 16. 22:24ㆍAndroid/UI-UX 디자인
728x90
반응형
1. SwipeRefreshLayout을 사용하기 위해 implementation 해준다.
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
2. 리사이클러뷰가 존재하는 xml에서 리사이클러뷰는 SwipeRefreshLayout으로 감싸준다.
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/SwipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0F0F0" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
3. 스와이프뷰에 setOnRefreshListener를 통해 리스트를 갱신하는 기능을 넣어준다.
view.Swipe_HomeF_SwipeRefresh.setOnRefreshListener {
// 리사이클러뷰와 연결한 배열을 초기화하고 수정하는 소스를 추가해준다.
// 배열이 변경되었다는 것을 리사이클러뷰에 알려준다
RecyclerView.adapter?.notifyDataSetChanged()
// 새로고침 아이콘을 멈춰준다. -> 넣어주지 않으면 무한로딩
view.Swipe_HomeF_SwipeRefresh.isRefreshing = false
}
728x90
반응형
'Android > UI-UX 디자인' 카테고리의 다른 글
[Android/Layout]RecyclerView 내에서 View Binding 사용하기 (0) | 2021.09.26 |
---|---|
[Android/WebView]기초 #1. 주소를 가져와 화면에 호출 (0) | 2021.09.23 |
[Android/Basic]설정화면 구현하기 (0) | 2021.05.12 |
[Android/Layout]DB 데이터를 Fragment 내 RecyclerView에 뿌리기(MS-SQL) (0) | 2021.05.08 |
[Android/Layout]Fragment에서 버튼을 생성하여 버튼 클릭 시 Activity로 intent하기 (0) | 2021.05.08 |