相关疑难解决方法(0)

使用Dagger 2的ViewModelProviders,无法掌握概念

我有这样的改造服务

public interface BrandsService {
    @GET("listBrand")
    Call<List<Brand>> getBrands();
}
Run Code Online (Sandbox Code Playgroud)

然后我有一个Repository来从这样的api获取数据

public class BrandsRepository {
    public static final String TAG = "BrandsRepository";
    MutableLiveData<List<Brand>> mutableLiveData;
    Retrofit retrofit;

    @Inject
    public BrandsRepository(Retrofit retrofit) {
        this.retrofit = retrofit;
    }

    public LiveData<List<Brand>> getListOfBrands() {
//       Retrofit retrofit = ApiManager.getAdapter();
        final BrandsService brandsService = retrofit.create(BrandsService.class);
        Log.d(TAG, "getListOfBrands: 00000000000 "+retrofit);

        mutableLiveData = new MutableLiveData<>();

        Call<List<Brand>> retrofitCall = brandsService.getBrands();
        retrofitCall.enqueue(new Callback<List<Brand>>() {
            @Override
            public void onResponse(Call<List<Brand>> call, Response<List<Brand>> response) {
                mutableLiveData.setValue(response.body());
            }

            @Override
            public void onFailure(Call<List<Brand>> call, Throwable t) …
Run Code Online (Sandbox Code Playgroud)

android retrofit dagger-2 android-viewmodel android-architecture-components

4
推荐指数
2
解决办法
3183
查看次数