【发布时间】:2018-10-08 13:10:06
【问题描述】:
onFailure 手机没网时可以重新通话吗?
代码:
private void ShowData() {
rv_categories.setVisibility(View.GONE);
txt_loading.setVisibility(View.VISIBLE);
Loading();
Retrofit retrofit = new Retrofit.Builder().baseUrl("*****").addConverterFactory(GsonConverterFactory.create()).build();
RetrofitService retrofitService = retrofit.create(RetrofitService.class);
Call<List<CategoriesModels>> call = retrofitService.get_categories();
call.enqueue(new Callback<List<CategoriesModels>>() {
@Override
public void onResponse(Call<List<CategoriesModels>> call, Response<List<CategoriesModels>> response) {
List<CategoriesModels> list = response.body();
for (CategoriesModels i : list) {
categoriesModels.add(new CategoriesModels(i.getId(), i.getTitle(), i.getPhoto(), i.getShortcut()));
}
Collections.shuffle(categoriesModels);
categoriesAdapter = new CategoriesAdapter(CategoriesActivity.this, categoriesModels);
rv_categories.setLayoutManager(new LinearLayoutManager(CategoriesActivity.this, LinearLayoutManager.VERTICAL, false));
rv_categories.setAdapter(categoriesAdapter);
rv_categories.setVisibility(View.VISIBLE);
txt_loading.setVisibility(View.GONE);
}
@Override
public void onFailure(Call<List<CategoriesModels>> call, Throwable t) {
//I want when there is no Internet try call again
}
});
}
如果我不能重新调用,还有其他方法吗?
【问题讨论】:
-
看看这个答案stackoverflow.com/a/32840088/9715339。这可能会有所帮助。
标签: android android-studio retrofit retrofit2