내 앱에는 할당 경로 목록이 있습니다. 경로가 웹에서 할당되었습니다. 보기에서 풀다운 후 목록이 업데이트되었습니다. 그러나, 내가 풀다 올 때마다 확대보기.새로 고침을 위해 스 와이프 추가 동적 목록의 레이아웃
보기 얻을 때마다 후 풀다운 지속적으로 확장이 새로 고침 스 와이프를 적용한 후 내 스크린 샷
입니다 :
이 새로 고침 스 와이프를 적용하기 전에 내 스크린 샷입니다 스 와이프하여 새로 고침하는 뷰.
이 내가 SwipeRefreshLayout
의 레이아웃 파일을 포함하는 방법입니다
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:background="?android:attr/selectableItemBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ui.activities.RoutesAssignActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeToRefreshLayoutId"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/md_white_1000"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
이 내 API 호출입니다 :
void getRoutes() {
Log.e("getRoutes", "=======getRoutes======== ");
final ApiService service = RestClient.getClient();
Call<ApiResponse> signedIn = service.getRoutesApi(getPreference().getToken());
signedIn.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(Response<ApiResponse> response) {
if (response.isSuccess()) {
ApiResponse result = response.body();
//error handling
if (result.getData() != null && result.getData().getRoutesList() != null) {
dialog.dismiss();
emptyHistory.setVisibility(View.GONE);
historyView.setVisibility(View.VISIBLE);
routesDatas = result.getData().getRoutesList();
setupRecyclerView(routesDatas);
} else if (result.getMsg().equalsIgnoreCase("Invalid token or Token has expired")) {
getPreference().removeLoginPreferences();
Intent intent = new Intent(RoutesAssignActivity.this, LoginActivity.class);
finish();
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
overridePendingTransition(0, 0);
startActivity(intent);
} else {
dialog.dismiss();
emptyHistory.setVisibility(View.VISIBLE);
historyView.setVisibility(View.GONE);
}
} else {
// response received but request not successful (like 400,401,403 etc)
//Handle errors
dialog.dismiss();
Snackbar.make(findViewById(android.R.id.content),
response.message(), Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Throwable t) {
dialog.dismiss();
showNetworkSettings();
Log.e("Errors :: getRoutes", "=======Status Code ======== " + t.getMessage());
}
});
}
지정 경로 여기에 업데이트 얻을 : onCreate
방법에서 routesDatas = result.getData().getRoutesList();
, 나는 getRoutes()
방법이라고 부른다 :
if (getNetworkStatus()) {
getRoutes();
} else {
showNetworkSettings();
}
I 설치 RecyclerView
로 : 나는 풀다운 할 때 지속적으로 매번 확장 얻을 뷰 그래서 내가 onCreate
방법에 Swipe to Refresh
을 적용
void setupRecyclerView(List<RoutesList> routes) {
dialog.dismiss();
FontIconTypefaceHolder.init(getAssets(), "fonts/MaterialIcons-Regular.ttf");
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
stickyHeaderListAdapter = new StickyHeaderListAdapter(routes, this);
recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).build());
final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(stickyHeaderListAdapter);
recyclerView.addItemDecoration(headersDecor);
recyclerView.setAdapter(stickyHeaderListAdapter);
}
.
if (getNetworkStatus()) {
getRoutes();
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getRoutes();
swipeRefreshLayout.setEnabled(false);
}
});
} else {
dialog.dismiss();
showNetworkSettings();
}
여기에 Swipe to Refresh
을 어떻게 구현합니까?
새로 고칠 때마다 recyclerView를 설정하지 마십시오. 설정 항목에 대한 어댑터에 메소드를 만들고'notifyDataSetChanged() '를 호출하십시오. 항목 크기가 다를 수 있으므로'recyclerView.setHasFixedSize (true);'는 필요하지 않습니다. 레이아웃에서'match_parent'를 모든 위젯의 높이로 사용하십시오. –
좋습니다, 제안 해 주셔서 감사합니다.즉,'setupRecyclerView' 메소드에서'notifyDataSetChanged'를 사용합니다. –
여기 목록 화면에서 '새로 고침'을 적용 할 때만보기가 확장됩니다. 그러나 홈 화면에서 목록 화면으로 이동하면보기가 정상적으로 보입니다. –