Android 如果改装未向Recyclerview返回任何数据,则启动新活动
我正在使用Recyclerview从服务器调用数据。 如果改装返回空数据,我想转到新活动。下面是我尝试过的代码Android 如果改装未向Recyclerview返回任何数据,则启动新活动,android,android-recyclerview,retrofit,Android,Android Recyclerview,Retrofit,我正在使用Recyclerview从服务器调用数据。 如果改装返回空数据,我想转到新活动。下面是我尝试过的代码 ApiInterface apiInterface = RetrofitInstance.getRetrofitInstance().create(ApiInterface2.class); Call<List<ImageList>> call = apiInterface.getImgData(userEmail); cal
ApiInterface apiInterface = RetrofitInstance.getRetrofitInstance().create(ApiInterface2.class);
Call<List<ImageList>> call = apiInterface.getImgData(userEmail);
call.enqueue(new Callback<List<ImageList>>() {
@Override
public void onResponse(Call<List<ImageList>> call, Response<List<ImageList>> response) {
if (response.isSuccessful()) {
if (response.body() != null) {
imageLists = response.body();
layoutManager = new LinearLayoutManager(MyListings.this);
//layoutManager = new GridLayoutManager(MyListings.this, 2);
rv.setLayoutManager(layoutManager);
adapter = new ListingsAdapter(imageLists, MyListings.this);
rv.addItemDecoration(new DividerItemDecoration(rv.getContext(), layoutManager.getOrientation()));
rv.setAdapter(adapter);
progressDialog.dismiss();
} else {
Intent intent = new Intent(MyListings.this, NoDataHereActivity.class);
startActivity(intent);
} } }
@Override
public void onFailure(@NonNull Call<List<ImageList>> call, @NonNull Throwable t) {
Toast.makeText(MyListings.this, "Failed!!" + t.getMessage(), Toast.LENGTH_LONG).show();
progressDialog.dismiss();
} });
ApiInterface ApiInterface=RefughtInstance.GetRefughtInstance().create(ApiInterface2.class);
Call Call=apinterface.getImgData(userEmail);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
if(response.body()!=null){
ImageList=response.body();
layoutManager=新的LinearLayoutManager(MyListings.this);
//layoutManager=新的GridLayoutManager(MyListings.this,2);
rv.设置布局经理(布局经理);
adapter=新的ListingsAdapter(ImageList,MyListings.this);
addItemDecoration(新的DividerItemDecoration(rv.getContext(),layoutManager.getOrientation());
rv.设置适配器(适配器);
progressDialog.disclose();
}否则{
Intent Intent=新的Intent(MyListings.this、NoDataHereActivity.class);
星触觉(意向);
} } }
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable t){
Toast.makeText(MyListings.this,“失败!!”+t.getMessage(),Toast.LENGTH\u LONG.show();
progressDialog.disclose();
} });
我可以通过应用此代码来解决此问题
ApiInterface apiInterface = RetrofitInstance.getRetrofitInstance().create(ApiInterface2.class);
Call<List<ImageList>> call = apiInterface.getImgData(userEmail);
call.enqueue(new Callback<List<ImageList>>() {
@Override
public void onResponse(Call<List<ImageList>> call, Response<List<ImageList>> response) {
if (response.isSuccessful()) {
if (response.body() != null && !response.body().isEmpty()) {
imageLists = response.body();
layoutManager = new LinearLayoutManager(MyListings.this);
//layoutManager = new GridLayoutManager(MyListings.this, 2);
rv.setLayoutManager(layoutManager);
adapter = new ListingsAdapter(imageLists, MyListings.this);
rv.addItemDecoration(new DividerItemDecoration(rv.getContext(), layoutManager.getOrientation()));
rv.setAdapter(adapter);
progressDialog.dismiss();
} else {
progressDialog.dismiss();
Intent intent = new Intent(MyListings.this, NoDataHereActivity.class);
startActivity(intent);
} } }
@Override
public void onFailure(@NonNull Call<List<ImageList>> call, @NonNull Throwable t) {
Toast.makeText(MyListings.this, "Failed!!" + t.getMessage(), Toast.LENGTH_LONG).show();
progressDialog.dismiss();
} });
ApiInterface ApiInterface=RefughtInstance.GetRefughtInstance().create(ApiInterface2.class);
Call Call=apinterface.getImgData(userEmail);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
if(response.body()!=null&&!response.body().isEmpty()){
ImageList=response.body();
layoutManager=新的LinearLayoutManager(MyListings.this);
//layoutManager=新的GridLayoutManager(MyListings.this,2);
rv.设置布局经理(布局经理);
adapter=新的ListingsAdapter(ImageList,MyListings.this);
addItemDecoration(新的DividerItemDecoration(rv.getContext(),layoutManager.getOrientation());
rv.设置适配器(适配器);
progressDialog.disclose();
}否则{
progressDialog.disclose();
Intent Intent=新的Intent(MyListings.this、NoDataHereActivity.class);
星触觉(意向);
} } }
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable t){
Toast.makeText(MyListings.this,“失败!!”+t.getMessage(),Toast.LENGTH\u LONG.show();
progressDialog.disclose();
} });
我可以通过应用此代码来解决此问题
ApiInterface apiInterface = RetrofitInstance.getRetrofitInstance().create(ApiInterface2.class);
Call<List<ImageList>> call = apiInterface.getImgData(userEmail);
call.enqueue(new Callback<List<ImageList>>() {
@Override
public void onResponse(Call<List<ImageList>> call, Response<List<ImageList>> response) {
if (response.isSuccessful()) {
if (response.body() != null && !response.body().isEmpty()) {
imageLists = response.body();
layoutManager = new LinearLayoutManager(MyListings.this);
//layoutManager = new GridLayoutManager(MyListings.this, 2);
rv.setLayoutManager(layoutManager);
adapter = new ListingsAdapter(imageLists, MyListings.this);
rv.addItemDecoration(new DividerItemDecoration(rv.getContext(), layoutManager.getOrientation()));
rv.setAdapter(adapter);
progressDialog.dismiss();
} else {
progressDialog.dismiss();
Intent intent = new Intent(MyListings.this, NoDataHereActivity.class);
startActivity(intent);
} } }
@Override
public void onFailure(@NonNull Call<List<ImageList>> call, @NonNull Throwable t) {
Toast.makeText(MyListings.this, "Failed!!" + t.getMessage(), Toast.LENGTH_LONG).show();
progressDialog.dismiss();
} });
ApiInterface ApiInterface=RefughtInstance.GetRefughtInstance().create(ApiInterface2.class);
Call Call=apinterface.getImgData(userEmail);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
if(response.body()!=null&&!response.body().isEmpty()){
ImageList=response.body();
layoutManager=新的LinearLayoutManager(MyListings.this);
//layoutManager=新的GridLayoutManager(MyListings.this,2);
rv.设置布局经理(布局经理);
adapter=新的ListingsAdapter(ImageList,MyListings.this);
addItemDecoration(新的DividerItemDecoration(rv.getContext(),layoutManager.getOrientation());
rv.设置适配器(适配器);
progressDialog.disclose();
}否则{
progressDialog.disclose();
Intent Intent=新的Intent(MyListings.this、NoDataHereActivity.class);
星触觉(意向);
} } }
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable t){
Toast.makeText(MyListings.this,“失败!!”+t.getMessage(),Toast.LENGTH\u LONG.show();
progressDialog.disclose();
} });
您的响应正文实际上是否为空?它可能只是空的。事实上这就是我想要的。你的响应体真的是空的吗?它可能只是空的。实际上这就是我想要的。