Following How to set SwipeRefreshLayout refreshing property using android data binding? I'm trying to bind SwipeRefreshLayout
using data binding but SwipeRefreshLayout's progress is not getting hide.
Below is my code that i'm using it:
ViewModel
public class StateViewModel extends BaseViewModel {
public MutableLiveData<Boolean> isLoading;
public void getItemStateDetails() {
isLoading.setValue(true);
scanTypePosition.setValue(0);
getCompositeDisposable().add(
getRepositoryManager().getItemStates()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onSuccess, this::onError));
}
private void onError(Throwable throwable) {
isLoading.setValue(false);
errorMsg.setValue(throwable.getMessage());
}
private void onSuccess(List<State> states) {
isLoading.setValue(false);
lstState.setValue(states);
}
}
Layout
<variable
name="stateModel"
type="story.stateupdate.stateselection.StateViewModel" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
apps:cardUseCompatPadding="true">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:onRefreshListener="@{() -> stateModel.getItemStateDetails()}"
app:refreshing="@{stateModel.isLoading}">
<android.support.v7.widget.RecyclerView
android:id="@+id/stateRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.v7.widget.CardView>
In the above code, the variable isLoading
is getting changed from true
to false
but the progress is still visible. Can anyone point out what mistake I'm doing?