使用MVP达到了代码的解耦性
view层
public interface IGoods { //搜索商品 回调结果 void GetGoods(List<ShopBean.DataBean> dlist); }
//model层的接口
/** * 1. 类的用途 * 2. @author chensi * 3. @date 2017/10/14 11:08 */ public interface IGoodsModel { void getGoods(Context context, IGoods iGoods, String name, int page); }
//继承model接口
/** * 1. 类的用途 * 2. @author chensi * 3. @date 2017/10/14 11:09 */ public class GoodsModel implements IGoodsModel{ Context context; IGoods iGoods; private List<ShopBean.DataBean> data; public GoodsModel(Context context, IGoods iGoods) { this.context = context; this.iGoods = iGoods; } @Override public void getGoods(Context context, IGoods iGoods, String name,int page) { //请求网路数据 if(name!=null&&!"".equals(name)){ getHttpGoods(name,page); }else{ Toast.makeText(context,"输入不能为空",Toast.LENGTH_SHORT).show(); } } private void getHttpGoods(String name,int page) { Map<String,String> map=new HashMap<>(); map.put("keywords",name); map.put("page",page+