Computer Science&Engineering/안드로이드
[안드로이드] 아래로 당겨 새로고침 Swipe refresh layout
EDDO
2021. 5. 14. 14:26
참고할 글이 있었는데 다소 오래된 것들이라 삽질을 좀 했다.
1. gradle 에 dependency 추가
dependencies {
// Swipe Refresh Layout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
}
2. ListView나 RecyclerView 감싸주기
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/content_srl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<ListView
android:id="@+id/content_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
3. java 파일에서 setOnRefreshListener 오버라이드 해주기.
public class NewsActivity extends AppCompatActivity {
private SwipeRefreshLayout mysrl;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mysrl = findViewById(R.id.content_srl);
mysrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// 새로고침시 동작
new RssThread().start();
// 종료
mysrl.setRefreshing(false);
}
});
}
}
참고
https://developer.android.com/jetpack/androidx/releases/swiperefreshlayout?hl=ko
Swiperefreshlayout | Android 개발자 | Android Developers
Swiperefreshlayout 스와이프하여 새로고침 UI 패턴을 구현합니다. 최근 업데이트 현재 안정화 버전 다음 버전 후보 베타 버전 알파 버전 2020년 7월 22일 1.1.0 - - 1.2.0-alpha01 종속 항목 선언 SwipeRefreshLayout
developer.android.com
반응형