본문 바로가기
프로그래밍 언어/안드로이드

[Android] 당겨서 새로고침 구현하기

by 블루데이제이 2019. 3. 19.
728x90
반응형

Android Studio에서

 

build.gradle에

 

dependencies{

...

implementation 'com.android.support:support-v4:버전'

}

 

새로고침을 적용할 뷰를 SwipeRefreshLayout로 감싼다.

<android.support.v4.widget.swiperefreshlayout< p="" style="box-sizing: border-box; margin: 0px; padding: 0px; list-style-type: none;"></android.support.v4.widget.swiperefreshlayout<>

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:id="@+id/swipe_layout">

 

 <recyclerview< p="" style="box-sizing: border-box; margin: 0px; padding: 0px; list-style-type: none;"></recyclerview<>

    ...

  />

 

 

SwipeRefreshLayout을 객체로 만들고 OnRefreshListener 인터페이스 등록

SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);

mSwipeRefreshLayout.setOnRefreshListener(this);

 

 

@Override

public void onRefresh() {

  // 새로고침 코드

  ...

  // 새로고침 완료  

  mSwipeRefreshLayout.setRefreshing(false);

}

728x90
반응형

'프로그래밍 언어 > 안드로이드' 카테고리의 다른 글

안드로이드 화면회전 방지하기  (0) 2022.09.30