主Activity
//实现view层的接口 并且重写接口的方法 public class MainActivity extends AppCompatActivity implements MainViewListener { RecyclerView third_recyclerview; LinearLayout third_pay_linear; CheckBox third_allselect; Button third_submit; TextView edittext, third_totalnum, third_totalprice; private MainPresenter presenter; private ShopAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); third_recyclerview = (RecyclerView) findViewById(R.id.third_recyclerview); third_pay_linear = (LinearLayout) findViewById(R.id.third_pay_linear); third_allselect = (CheckBox) findViewById(R.id.third_allselect); third_totalprice = (TextView) findViewById(R.id.third_totalprice); edittext = (TextView) findViewById(R.id.edittext); third_totalnum = (TextView) findViewById(R.id.third_totalnum); third_submit = (Button) findViewById(R.id.third_submit); presenter = new MainPresenter(this); presenter.getData(); adapter = new ShopAdapter(this); LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); third_recyclerview.setLayoutManager(manager); third_recyclerview.setAdapter(adapter); third_allselect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { adapter.selectAll(third_allselect.isChecked()); } }); adapter.setListener(new ShopAdapter.UpdateUiListener() { @Override public void setTotal(String total, String num, boolean allCheck) { third_allselect.setChecked(allCheck); third_totalnum.setText(num); third_totalprice.setText(total); } }); third_submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, WeiXin.class); startActivity(intent); } }); } @Override public void succer(ShopBean bean) { adapter.add(bean); } @Override public void Defeat(Exception e) { Toast.makeText(this, "error", Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); presenter.detach(); } }主布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.zhangyongbo.erjiliebaio.MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/third_recyclerview" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <LinearLayout android:id="@+id/third_pay_linear" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="#FFFFFF" android:gravity="center_vertical" android:orientation="horizontal"> <CheckBox android:id="@+id/third_allselect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/margin_10dp" android:checked="false" android:drawableLeft="@mipmap/shopcart_selected" android:drawablePadding="@dimen/padding_5dp" android:text="全选" /> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <TextView android:id="@+id/third_totalprice" android:layout_width="200dp" android:layout_height="wrap_content" android:paddingLeft="@dimen/padding_10dp" android:paddingTop="@dimen/padding_10dp" android:text="总价:" android:textColor="@color/cblack" android:textSize="@dimen/common_font_size_16" /> <TextView android:id="@+id/third_totalnum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="@dimen/padding_10dp" android:paddingLeft="@dimen/padding_10dp" android:text="共0件商品" android:textColor="@color/cblack" android:textSize="@dimen/common_font_size_14" /> </LinearLayout> <Button android:id="@+id/third_submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="@dimen/margin_10dp" android:background="@drawable/login_btn" android:paddingBottom="@dimen/padding_10dp" android:paddingLeft="@dimen/margin_30dp" android:paddingRight="@dimen/margin_30dp" android:paddingTop="@dimen/padding_10dp" android:text="去结算" android:textColor="#000000" /> </LinearLayout> </LinearLayout>View层
public interface MainViewListener { void succer(ShopBean bean);//成功的方法 void Defeat(Exception e);//失败的方法 }modle层
nodle的类
public class MainModel { //获取网路数据 传入Modle的接口 public void getData(final MainModelCallBack callBack) { OkhttpUtils.getInstance().asy(null, "http://120.27.23.105/product/getCarts?uid=100", new AbstractUiCallBack<ShopBean>() { @Override public void success(ShopBean shopBean) { //这里用接口的的对象去调用接口的方法 callBack.succer(shopBean); } @Override public void failure(Exception e) { //这里用接口的的对象去调用接口的方法 callBack.Defeat(e); } }); } }modle的接口
public interface MainModelCallBack { void succer(ShopBean bean);//成功的方法 void Defeat(Exception e);//失败的方法 }presenter层
public class MainPresenter { //初始化 Modle层的类 和View层的接口 MainModel mainModel; //modle的类 MainViewListener mainViewListener;//View层的接口 //给有参构造 只给接口 不给Modle层 public MainPresenter(MainViewListener mainViewListener) { this.mainViewListener = mainViewListener; this.mainModel = new MainModel(); } //获取参数 New出来Modle层的接口 public void getData() { mainModel.getData(new MainModelCallBack() { @Override public void succer(ShopBean bean) { //判断数据是否请求成功 请求成功的了 // 就调取成功的方法 否则就是失败 那就调取失败的方法 if (mainViewListener != null) {//这是成功的方法 mainViewListener.succer(bean); } } @Override public void Defeat(Exception e) {//这是失败的方法 if (mainViewListener != null) { mainViewListener.Defeat(e); } } }); } /** * 防止内存泄漏 */ public void detach() { mainViewListener = null; } }下面是购物车的自定义View用于加减号
//这是购物车的自定义View 用来设置购物车的加减号 public class plusview extends LinearLayout { Button revserse,tianjian; EditText edittext; private int mcount = 1;//定义一个常量 用于购物车就入时默认显示为1 public plusview(Context context) { super(context); } public plusview(Context context, AttributeSet attributeSet){ super(context,attributeSet); //首先加载布局文件 View view = View.inflate(context, R.layout.plus_layout,null); //初始化控件 revserse = view.findViewById(R.id.revserse);//减号 tianjian = view.findViewById(R.id.tianjian);//加好 edittext = view.findViewById(R.id.edittext);//加号减号中间的输入框 //控件初始化玩之后 控件设置点击事件 revserse.setOnClickListener(new OnClickListener() { //减号的点击事件 @Override public void onClick(View view) { String trims = edittext.getText().toString().trim();//获取输入框的值去掉空格 int coun = Integer.valueOf(trims);//把从输入框的得到的值转换成整形 if (coun>1){ mcount = coun-1; edittext.setText(mcount+""); if (listener!=null){ listener.click(mcount); } } } }); //加号的点击事件 tianjian.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String trim = edittext.getText().toString().trim();//获取输入框的值去掉空格 int coun = Integer.valueOf(trim)+1;//把从输入框的得到的值转换成整形 mcount = coun; edittext.setText(coun+""); if (listener!=null){ listener.click(coun); } } }); //输入框的点击事件 edittext.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { } }); addView(view); //添加布局 } public plusview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void setEditText(int num){ if(edittext != null){ edittext.setText(num+""); } } public ClickListener listener; public void setListener(ClickListener listener ){ this.listener=listener; } /** * 加减号的点击事件 */ public interface ClickListener{ public void click(int coun); } }购物车的适配器
//适配器 public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ViewHolder> { private Context context;//传入上下文 private List<ShopBean.DataBean.ListBean> list;//bean包的集合 //存放商家的集合 private Map<String, String> map = new HashMap<>(); //有参构造 public ShopAdapter(Context context) { this.context = context; } /** * 添加数据并更新 */ public void add(ShopBean bean) { //判段如果list是空的 if (this.list == null) { //那就把listNew出来 this.list = new ArrayList<>(); } //遍历商家 for (ShopBean.DataBean shop : bean.getData()) { map.put(shop.getSellerid(), shop.getSellerName()); // 遍历商品 for (int i = 0; i < shop.getList().size(); i++) { this.list.add(shop.getList().get(i)); } } setFirst(this.list); //控制是否显示商家 notifyDataSetChanged();//更新数据 } /** * 设置数据源, 控制显示商家 * * @param list 这里把集合给setFirst这个方法就是要设置商品的显示与阴藏 */ private void setFirst(List<ShopBean.DataBean.ListBean> list) { //这里判断 如果集合的字符大于0 你就默认显示一个商家 if (list.size() > 0) { list.get(0).setIsFirst(1); //这是默认显示商家 for (int i = 1; i < list.size(); i++) { //这是For循环把集合里的所有元素循出来 if (list.get(i).getSellerid() == list.get(i - 1).getSellerid()) { //如果俩个商品是同一个商家的那么就让这两个商品只显示一个商家 list.get(i).setIsFirst(2); } else { //如果不是 就两个都显示 list.get(i).setIsFirst(1); if (list.get(i).isItemSelected()) { list.get(i).setShopSelected(list.get(i).isItemSelected()); } } } } } /** * 加载布局文件 */ @Override public ShopAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = View.inflate(context, R.layout.adapter_layout, null); //添加到ViewHolder里 return new ViewHolder(view); } @Override public void onBindViewHolder(final ShopAdapter.ViewHolder holder, final int position) { // 显示商品图片 if (list.get(position).getIsFirst() == 1) { //显示商家 VISIBLE显示商品 holder.shop_checkbox.setVisibility(View.VISIBLE);//显示商家 holder.tv_item_shopcart_shopname.setVisibility(View.VISIBLE);//显示商家 holder.shop_checkbox.setChecked(list.get(position).isShopSelected()); // 显示商家的名称 // list.get(position).getSellerid() 取到商家的id // map.get()取到 商家的名称 holder.tv_item_shopcart_shopname.setText(map.get(String.valueOf(list.get(position).getSellerid()))); } else { holder.shop_checkbox.setVisibility(View.GONE);//隐藏商家 holder.tv_item_shopcart_shopname.setVisibility(View.GONE);//隐藏商家 } //控制 商品的 checkbox holder.item_checkbox.setChecked(list.get(position).isItemSelected()); //这是分割 由于接口中的图片是连这的所以必须要分割 String[] url = list.get(position).getImages().split("\\|"); // 从分割完之后返回的数组中设置所要显示的图片 ImageLoader.getInstance().displayImage(url[0], holder.item_pic); //设置所要显示的文字 也是商家 holder.item_name.setText(list.get(position).getTitle()); //设置所要显示的价格 holder.item_price.setText(list.get(position).getPrice() + ""); //计算完所友的商品总价后在这设置显示 holder.plus_view_id.setEditText(list.get(position).getNum()); // 商家的checkbox 多选框 holder.shop_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { list.get(position).setShopSelected(holder.shop_checkbox.isChecked()); for (int i = 0; i < list.size(); i++) { if (list.get(position).getSellerid() == list.get(i).getSellerid()) { list.get(i).setItemSelected(holder.shop_checkbox.isChecked()); } } notifyDataSetChanged();//更新数据源 sum(list);//计算总价 } }); // 商品的checkbox 多选框 holder.item_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { list.get(position).setItemSelected(holder.item_checkbox.isChecked()); for (int i = 0; i < list.size(); i++) { for (int j = 0; j < list.size(); j++) { if (list.get(i).getSellerid() == list.get(j).getSellerid() && !list.get(j).isItemSelected()) { list.get(i).setShopSelected(false); break; } else { list.get(i).setShopSelected(true); } } } notifyDataSetChanged();//更新数据源 sum(list);//计算总价 } }); //删除的点击事件 holder.item_del.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //从集合中移除商家信息 list.remove(position); setFirst(list); notifyDataSetChanged();//更新数据 sum(list);//算总价 } }); //加减号 holder.plus_view_id.setListener(new plusview.ClickListener() { @Override public void click(int count) { list.get(position).setNum(count); notifyDataSetChanged();//更新适配器 sum(list);//计算总价 } }); } @Override public int getItemCount() { return list == null ? 0 : list.size();//三元运算符 } /** * 计算总价 * * @param list */ private void sum(List<ShopBean.DataBean.ListBean> list) { int totalNum = 0; float totalMoney = 0.0f; boolean allCheck = true; for (int i = 0; i < list.size(); i++) { if (list.get(i).isItemSelected()) { totalNum += list.get(i).getNum(); totalMoney += list.get(i).getNum() * list.get(i).getPrice(); } else { allCheck = false; } } listener.setTotal(totalMoney + "", totalNum + "", allCheck); } public void selectAll(boolean cl) { for (int i = 0; i < list.size(); i++) { list.get(i).setShopSelected(cl); list.get(i).setItemSelected(cl); } notifyDataSetChanged(); sum(list); } public class ViewHolder extends RecyclerView.ViewHolder { View view, item_del; plusview plus_view_id; CheckBox shop_checkbox, item_checkbox; TextView tv_item_shopcart_shopname, item_price, item_name, tv_item_shopcart_cloth_size; ImageView item_pic; public ViewHolder(View itemView) { super(itemView); view = itemView.findViewById(R.id.view); item_del = itemView.findViewById(R.id.item_del); shop_checkbox = itemView.findViewById(R.id.shop_checkbox); item_checkbox = itemView.findViewById(R.id.item_checkbox); tv_item_shopcart_shopname = itemView.findViewById(R.id.tv_item_shopcart_shopname); item_price = itemView.findViewById(R.id.item_price); item_name = itemView.findViewById(R.id.item_name); tv_item_shopcart_cloth_size = itemView.findViewById(R.id.tv_item_shopcart_cloth_size); item_pic = itemView.findViewById(R.id.item_pic); plus_view_id = itemView.findViewById(R.id.plus_view_id); } } public UpdateUiListener listener; public void setListener(UpdateUiListener listener) { this.listener = listener; } //更新接口数据 public interface UpdateUiListener { public void setTotal(String total, String num, boolean allCheck); } }
子布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/cwhite" android:orientation="vertical"> <LinearLayout android:id="@+id/ll_shopcart_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="@dimen/margin_10dp" android:background="@color/background_color" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <!-- 商店checkbox --> <CheckBox android:id="@+id/shop_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="@dimen/margin_10dp" android:paddingLeft="@dimen/margin_15dp" android:paddingRight="@dimen/margin_15dp" android:paddingTop="@dimen/margin_10dp" android:src="@mipmap/shopcart_selected" /> <!-- 商店明晨 --> <TextView android:id="@+id/tv_item_shopcart_shopname" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@mipmap/shopcart_shop" android:drawablePadding="@dimen/padding_5dp" android:padding="@dimen/padding_10dp" android:text="宝儿家服装" android:textColor="@color/cblack" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="@dimen/margin_1dp" android:background="@color/background_color" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <!-- 商品 checkbox --> <CheckBox android:id="@+id/item_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/margin_15dp" android:src="@mipmap/shopcart_selected" /> <!-- 商品图片 --> <ImageView android:id="@+id/item_pic" android:layout_width="60dp" android:layout_height="60dp" android:layout_margin="@dimen/margin_10dp" /> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <TextView android:id="@+id/item_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥185" android:textColor="@color/main_red_text" android:textSize="@dimen/common_font_size_14" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/margin_5dp" android:layout_marginTop="@dimen/margin_5dp"> <TextView android:id="@+id/item_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="颜色:黑色" android:textColor="@color/cblack" android:textSize="@dimen/common_font_size_12" /> <TextView android:id="@+id/tv_item_shopcart_cloth_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/margin_10dp" android:text="尺寸:XL" android:textColor="@color/cblack" android:textSize="@dimen/common_font_size_12" /> </LinearLayout> <com.zhangyongbo.erjiliebaio.PlusView.plusview android:id="@+id/plus_view_id" android:layout_width="100dp" android:layout_height="wrap_content"> </com.zhangyongbo.erjiliebaio.PlusView.plusview> </LinearLayout> <View android:layout_width="@dimen/margin_1dp" android:layout_height="match_parent" android:layout_marginBottom="@dimen/padding_10dp" android:layout_marginTop="@dimen/padding_10dp" android:background="@color/splitline_color" /> <ImageView android:id="@+id/item_del" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/margin_20dp" android:src="@mipmap/shopcart_delete" /> </LinearLayout> </LinearLayout> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="@dimen/margin_1dp" android:background="@color/background_color" /> </LinearLayout>加减号的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:id="@+id/revserse" android:layout_width="20dp" android:layout_height="20dp" android:background="#FF00" android:text="-" /> <EditText android:id="@+id/edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="number" android:text="1" /> <Button android:id="@+id/tianjian" android:layout_width="20dp" android:layout_height="20dp" android:background="#FF00" android:text="+" /> </LinearLayout>
我这里用的是Imageloade需要配置文件下面是我的配置文件
/** * 这是配置ImageLoage的 配置完要在清单文件中注册 */ public class MyApps extends Application { @Override public void onCreate() { super.onCreate(); File file = new File(Environment.getExternalStorageDirectory().getPath()+"Images0718"); ImageLoaderConfiguration conn = new ImageLoaderConfiguration.Builder(this) .threadPoolSize(5) .memoryCacheExtraOptions(80, 80) .memoryCacheSize(2 * 1024 * 1024) .threadPriority(1000) .diskCacheFileNameGenerator(new Md5FileNameGenerator()) .diskCacheSize(50 * 1024 * 1024) .build(); ImageLoader.getInstance().init(conn); } }我用的是OkHttp请求下面是我封装的OkHttp
//Okhttp 单例 范型的封装 public abstract class AbstractUiCallBack<T> implements Callback { /** * 成功回调 * @param t */ public abstract void success(T t); /** * 失败回调 * @param e */ public abstract void failure(Exception e); private Handler handler = null ; private Class clazz ; public AbstractUiCallBack(){ handler = new Handler(Looper.getMainLooper()); // 得到的是一个 AbstractUiCallBack<T> 的Type Type type = getClass().getGenericSuperclass() ; // 得到的是T的实际Type Type [] arr = ((ParameterizedType)type).getActualTypeArguments() ; clazz = (Class) arr[0] ; } @Override public void onFailure(Call call, IOException e) { failure(e); } @Override public void onResponse(Call call, Response response) throws IOException { try { String result = response.body().string(); System.out.println("result = " + result); Gson gson = new Gson(); final T t = (T) gson.fromJson(result,clazz); handler.post(new Runnable() { @Override public void run() { success(t); } }); } catch (IOException e) { e.printStackTrace(); failure(e); } catch (JsonSyntaxException e) { e.printStackTrace(); failure(e); } } }
//Okhttp 单例 范型的封装 public class OkhttpUtils { private static OkhttpUtils okhttpUtils = null; private OkhttpUtils() { } public static OkhttpUtils getInstance() { if (okhttpUtils == null) { okhttpUtils = new OkhttpUtils(); client = new OkHttpClient.Builder() .readTimeout(20, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .connectTimeout(20, TimeUnit.SECONDS) .addInterceptor(new LoggingInterceptor()) .build(); } return okhttpUtils; } private static OkHttpClient client; public void asy(Map<String, String> params, String url, AbstractUiCallBack callBack) { Request request = null; if (params != null) { FormBody.Builder builder = new FormBody.Builder(); for (Map.Entry<String, String> entry : params.entrySet()) { builder.add(entry.getKey(), entry.getValue()); } FormBody body = builder.build(); request = new Request.Builder() .url(url) .post(body) .build(); } else { request = new Request.Builder() .url(url) .build(); } client.newCall(request).enqueue(callBack); } private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png"); public static void postFile(Map<String, String> map, String url, File file, AbstractUiCallBack callBack) { String[] array = file.getAbsolutePath().split("\\/"); MultipartBody.Builder builder = new MultipartBody.Builder(); builder.setType(MultipartBody.FORM); for (Map.Entry<String, String> entry : map.entrySet()) { builder.addFormDataPart(entry.getKey(), entry.getValue()); } builder.addFormDataPart("imageFileName", array[array.length - 1]); if (file.exists() && file.length() > 0) { builder.addFormDataPart("image", array[array.length - 1], RequestBody.create(MEDIA_TYPE_PNG, file)); } MultipartBody body = builder.build(); Request request = new Request.Builder() .url(url) .post(body) .build(); client.newCall(request).enqueue(callBack); } }下面是拦截器的封装
//拦截器 public class LoggingInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); long t1 = System.nanoTime(); // logger.info(String.format("Sending request %s on %s%n%s", // request.url(), chain.connection(), request.headers())); Response response = chain.proceed(request); long t2 = System.nanoTime(); // logger.info(String.format("Received response for %s in %.1fms%n%s", // response.request().url(), (t2 - t1) / 1e6d, response.headers())); System.out.println("t2 = " + (t2-t1)); return response; } }我这里用到了一些图片需要自己去阿里巴巴矢量图标库下载
还需要在drawble下面配置一下这个
<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportHeight="108" android:viewportWidth="108"> <path android:fillColor="#26A69A" android:pathData="M0,0h108v108h-108z" /> <path android:fillColor="#00000000" android:pathData="M9,0L9,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,0L19,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M29,0L29,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M39,0L39,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M49,0L49,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M59,0L59,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M69,0L69,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M79,0L79,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M89,0L89,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M99,0L99,108" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,9L108,9" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,19L108,19" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,29L108,29" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,39L108,39" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,49L108,49" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,59L108,59" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,69L108,69" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,79L108,79" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,89L108,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M0,99L108,99" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,29L89,29" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,39L89,39" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,49L89,49" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,59L89,59" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,69L89,69" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M19,79L89,79" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M29,19L29,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M39,19L39,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M49,19L49,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M59,19L59,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M69,19L69,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> <path android:fillColor="#00000000" android:pathData="M79,19L79,89" android:strokeColor="#33FFFFFF" android:strokeWidth="0.8" /> </vector>第二个
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="@dimen/height_200dp"></corners>
<solid android:color="@color/pressed_icon_color"></solid>
</shape>
第三个
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="@dimen/height_200dp"></corners> <stroke android:color="@color/background_color" android:width="1dp"></stroke> </shape>在Values下配置Color
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> <color name="cwhite">#FFFFFF</color> <color name="title_bg">#FDE23D</color> <color name="tab_bg">#FFFFFF</color> <color name="tab_normal_textcolor">#373737</color> <color name="tab_selected_textcolor">#FDE23D</color> <color name="coffer">#442509</color> <color name="pressed_icon_color">#e53e42</color> <color name="background_color">#f6f6f6</color> <color name="main_red_text">#e53e42</color> <dimen name="padding_20dp">20dp</dimen> <color name="splitline_color">#dddddd</color> <color name="cblack">#000000</color> </resources>配置diment
<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> <dimen name="margin_10dp">10dp</dimen> <dimen name="padding_5dp">5dp</dimen> <dimen name="padding_10dp">10dp</dimen> <dimen name="common_font_size_16">16sp</dimen> <dimen name="common_font_size_14">14sp</dimen> <dimen name="height_200dp">200dp</dimen> <dimen name="margin_30dp">30dp</dimen> <dimen name="margin_15dp">15dp</dimen> <dimen name="margin_1dp">1dp</dimen> <dimen name="margin_5dp">5dp</dimen> <dimen name="common_font_size_12">12sp</dimen> <dimen name="padding_2dp">2dp</dimen> <dimen name="margin_20dp">20dp</dimen> </resources>
Bean包需要自己写三个属性
// 1 显示商家 2 隐藏商家 private int isFirst; // true 表示商家选中 false 相反 private boolean shopSelected; // true 表示 当前商品是选中的 false 相反 private boolean itemSelected;
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />所用到的依赖
compile 'com.squareup.okhttp3:okhttp:3.2.0' compile 'com.squareup.okio:okio:1.7.0' compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' compile 'com.jakewharton:butterknife:7.0.0' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
本文详细介绍了一个基于MVP架构的购物车功能实现方案,包括主Activity、View层接口、Model层接口及其实现类、Presenter层类等核心组件的设计与代码实现。
1612

被折叠的 条评论
为什么被折叠?



