我一直在撞墙,我无法理解为什么会这样.我正在使用Android的新建筑组件,我在使用对象列表更新LiveData时遇到问题.我有两个旋转器.当我更改第一个选项时,第二个必须更改其内容.但最后一部分没有发生.谁能帮我?
State.java
@Entity(tableName = "states")
public class State{
@PrimaryKey(autoGenerate = false)
private int id;
private String name;
@ColumnInfo(name = "countryId")
private String CountryId;
@Ignore
private Object geoCenter, geoLimit;
public State(){
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCountryId() {
return CountryId;
}
public void setCountryId(String countryId) {
CountryId = countryId;
}
} …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我使用mvvm模式跟随架构组件.我的应用程序进行网络调用以显示天气信息.正在从存储库进行调用,该存储库返回对视图模型的响应的居住数据,其中由我的主要活动观察到.
该应用程序工作正常,除了一个条件,每当我断开互联网测试失败的情况下,它会根据需要膨胀错误视图
在错误视图中我有一个重试按钮,这使得方法调用再次观察视图模型(这个方法也是第一次被oncreate()调用,这有效)
即使在打开互联网并点击侦听observable的重试按钮后,数据也会变为空.
我不知道为什么.请任何人帮助
REPOSITORY
@Singleton public class ContentRepository {
@Inject AppUtils mAppUtils;
private RESTService mApiService;
@Inject public ContentRepository(RESTService mApiService) {
this.mApiService = mApiService;
}
public MutableLiveData<ApiResponse<WeatherModel>> getWeatherListData() {
final MutableLiveData<ApiResponse<WeatherModel>> weatherListData = new MutableLiveData<>();
mApiService.getWeatherList().enqueue(new Callback<WeatherModel>() {
@Override public void onResponse(Call<WeatherModel> call, Response<WeatherModel> response) {
weatherListData.setValue(new ApiResponse<>(response.body()));
}
@Override public void onFailure(Call<WeatherModel> call, Throwable t) {
weatherListData.setValue(new ApiResponse<>(t));
}
});
return weatherListData;
}
}
Run Code Online (Sandbox Code Playgroud)
视图模型
public class HomeViewModel extends AndroidViewModel {
private final LiveData<ApiResponse<WeatherModel>> weatherListObservable;
@Inject public HomeViewModel(Application …Run Code Online (Sandbox Code Playgroud) android android-livedata android-viewmodel android-architecture-components
android ×2
android-architecture-components ×1
android-room ×1
dagger ×1
dagger-2 ×1
viewmodel ×1