아래로 당겨 새로고침 : SwipeRefreshLayout
2021. 9. 2. 00:21
1. build.gradle에 추가
// Swipe Refresh Layout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
2. xml layout 작성
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
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" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
RecyclerView, ListView 등 새로고침 될 영역을 SwipeRefreshLayout에 넣어준다.
3. Activity 작성
binding.swipeRefreshLayout.setOnRefreshListener {
binding.swipeRefreshLayout.isRefreshing = false
// todo 새로고침할 데이터
}
swipeRefreshLayout에 OnRefreshListener를 달아준다.
위 코드에서는 ViewBinding 후 작성하였다.
isRefreshing을 false로 해주어야 새로고침 후에 돌아가는 아이콘을 지워줄 수 있다.
아래에 새로고침 할 내용을 적어주면 된다.
728x90
'💻개발 > Android' 카테고리의 다른 글
ViewModel & LiveData (0) | 2021.09.20 |
---|---|
MVC, MVP, MVVM 간단 정리 (0) | 2021.09.07 |
[오류해결] Runtime JAR files in the classpath should have the same version. These files were found in the classpath: (0) | 2021.08.26 |
Koin Setup : 코인 셋업하기 (0) | 2021.08.26 |
coroutines Setup : 코루틴 셋업하기 (0) | 2021.08.26 |