连接Retrofit层后续

此博客展示了Android项目中一个Model类的代码。包含包声明、多个类的导入,如Api、ApiServer、DataBean等,还涉及Retrofit相关工具类的使用,最后定义了ShowModel类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.bw.com.zuoye0316.model;

import android.util.Log;

import com.bw.com.zuoye0316.api.Api;
import com.bw.com.zuoye0316.api.ApiServer;
import com.bw.com.zuoye0316.bean.DataBean;
import com.bw.com.zuoye0316.bean.JsonBean;
import com.bw.com.zuoye0316.utils.RetrofitUtils;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

ic class ShowModel {

//接口
public interface OnShowLisenter{
    void onShow(List<DataBean> data);
}
private OnShowLisenter showLisenter;

public void setOnShowLisenter(OnShowLisenter showLisenter){
    this.showLisenter=showLisenter;
}



public void relected(int page) {
    ApiServer apiServer = RetrofitUtils.getInstance().getApiServer(Api.url, ApiServer.class);
    Call<List<JsonBean>> call = apiServer.getUrl(page+".json");
  call.enqueue(new Callback<List<JsonBean>>() {
      @Override
      public void onResponse(Call<List<JsonBean>> call, Response<List<JsonBean>> response) {
          List<JsonBean> body = response.body();
          JsonBean jsonBean = body.get(0);
          Log.i("zzz",jsonBean.toString());
          List<DataBean> data = jsonBean.getData();
          //判断接口
          if (showLisenter!=null){
              showLisenter.onShow(data);
          }

      }

      @Override
      public void onFailure(Call<List<JsonBean>> call, Throwable t) {

      }
  });
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值