프로그래밍/Android
[Android] Swipe해서 새로고침하기
Youngs_
2022. 3. 29. 16:16
build.gradle
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") // 스와이프로 새로고침 가능하게 해주는 레이아웃
액티비티의 xml코드
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/swipe"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toLeftOf="@id/title">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/listview"
tools:listitem="@layout/recylerview_book_item"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
코틀린 코드
binding.swipe.setOnRefreshListener {
updateList() // 목록을 다시 가져오는 함수
binding.swipe.isRefreshing = false // 새로고침 마크 지우기
}