利用MVP实现购物车提交订单
来源:互联网 发布:数据分析发展史 编辑:程序博客网 时间:2024/05/16 19:33
效果图如下:
技术要求:
MVP,okhttp二次封装,单例模式,图片加载:imageLoader/glide/picaso,recyclerView展示数据,自定义条目点击事件,上拉加载和下拉刷新控件的使用,购物车,订单,TabLayout
所需要的依赖:
compile 'com.squareup.okhttp3:okhttp:3.9.0'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'org.greenrobot:eventbus:3.1.1'
compile 'com.android.support:design:26.1.0'
所需要的权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
代码如下:
import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationSet;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;import android.widget.ImageView;public class SplashActivity extends AppCompatActivity { private ImageView img; private AnimationSet animationSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img = (ImageView) findViewById(R.id.img); initAnimates();//初始化动画 /** * 动画的监听事件 */ animationSet.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { /** * 结束监听的事件 */ Intent intent = new Intent(SplashActivity.this, DetailsActivity.class); startActivity(intent); finish(); } @Override public void onAnimationRepeat(Animation animation) { } }); } //初始化动画 private void initAnimates() { //创建属性动画对象 animationSet = new AnimationSet(true); /** 参数1:从哪个旋转角度开始 * 参数2:转到什么角度 * 后4个参数用于设置围绕着旋转的圆的圆心在哪里 * 参数3:确定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标 * 参数4:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴 * 参数5:确定y轴坐标的类型 * 参数6:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴 */ RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setDuration(3000);// rotateAnimation.setFillAfter(true); animationSet.addAnimation(rotateAnimation); /** * 移动 * 参数1~2:x轴的开始位置 * 参数3~4:y轴的开始位置 * 参数5~6:x轴的结束位置 * 参数7~8:x轴的结束位置 */ TranslateAnimation translateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 3f); translateAnimation.setDuration(3000);// translateAnimation.setFillAfter(true); animationSet.addAnimation(translateAnimation); //创建一个AnimationSet对象,参数为Boolean型, //true表示使用Animation的interpolator,false则是使用自己的 //创建一个AlphaAnimation对象,参数从完全的透明度,到完全的不透明 AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); //设置动画执行的时间 alphaAnimation.setDuration(3000);// alphaAnimation.setFillAfter(true); animationSet.addAnimation(alphaAnimation); //参数1:x轴的初始值 //参数2:x轴收缩后的值 //参数3:y轴的初始值 //参数4:y轴收缩后的值 //参数5:确定x轴坐标的类型 //参数6:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴 //参数7:确定y轴坐标的类型 //参数8:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴 ScaleAnimation scaleAnimation = new ScaleAnimation( 2, 1f, 2, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(3000);// scaleAnimation.setFillAfter(true); animationSet.addAnimation(scaleAnimation); //使动画静止 animationSet.setFillAfter(true); img.startAnimation(animationSet); }}
DetailsActivity.java(商品详情页面)
import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import android.widget.Toast;import com.bwie.myapplication.bean.JsonDetailsBean;import com.bwie.myapplication.interfaces.IAddShopCarPresenter;import com.bwie.myapplication.interfaces.IDetailsPresenter;import com.bwie.myapplication.presenter.AddShopCarPresenter;import com.bwie.myapplication.presenter.DetailsPresenter;import com.nostra13.universalimageloader.core.ImageLoader;public class DetailsActivity extends AppCompatActivity implements IDetailsPresenter, IAddShopCarPresenter { private ImageView img; private TextView title; private TextView price; private Button btnShopCar; private Button btnJoin; private DetailsPresenter detailsPresenter; private String uid = "3384"; private String pid = "2"; private AddShopCarPresenter addShopCarPresenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details); detailsPresenter = new DetailsPresenter(this); addShopCarPresenter = new AddShopCarPresenter(this); initView(); initData(); /** * 点击购物车跳转页面 */ btnShopCar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(DetailsActivity.this, SearchShopCarActivity.class); startActivity(intent); } }); //点击加入加入购物车的点击事件 btnJoin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { addShopCarPresenter.receive("3384", "2"); } }); } private void initData() { detailsPresenter.receive(pid); } private void initView() { img = (ImageView) findViewById(R.id.img); title = (TextView) findViewById(R.id.title); price = (TextView) findViewById(R.id.price); btnShopCar = (Button) findViewById(R.id.btnShopCar);//购物车 btnJoin = (Button) findViewById(R.id.btnJoin);//加入购物车 } @Override public void onSuccess(JsonDetailsBean.DataBean data) { String[] split = data.getImages().split("\\|"); ImageLoader.getInstance().displayImage(split[0], img); title.setText(data.getTitle()); price.setText(data.getPrice() + ""); } @Override public void onASuccess(String msg) { Toast.makeText(DetailsActivity.this, msg, Toast.LENGTH_SHORT).show(); } @Override public void onAFailed() { } @Override public void onFailed() { }}
SearchShopCarActivity.java(结算页面)
import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.CheckBox;import android.widget.ExpandableListView;import android.widget.RelativeLayout;import android.widget.TextView;import com.bwie.myapplication.adapter.MyAdapter;import com.bwie.myapplication.adapter.PriceAndCountEvent;import com.bwie.myapplication.bean.JsonShopCarBean;import com.bwie.myapplication.interfaces.IShopCarPresenter;import com.bwie.myapplication.presenter.SearchShopCarPresenter;import org.greenrobot.eventbus.EventBus;import org.greenrobot.eventbus.Subscribe;import java.util.ArrayList;import java.util.List;public class SearchShopCarActivity extends AppCompatActivity implements IShopCarPresenter { private ExpandableListView ex; private CheckBox selectAll; private TextView allPrice; private TextView count; private int uid = 3384; private SearchShopCarPresenter searchShopCarPresenter; private List<JsonShopCarBean.DataBean> groupList = new ArrayList<>();//商家店铺 private List<List<JsonShopCarBean.DataBean.ListBean>> childList = new ArrayList<>();//商品 private MyAdapter myAdapter; private RelativeLayout btnMoney; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); initView(); /** * 用于传控件, * 需要导入依赖才可以进行传送 */ EventBus.getDefault().register(this); //全选/全不选 selectAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //设置全选 myAdapter.changeAllListCbState(selectAll.isChecked()); } }); searchShopCarPresenter = new SearchShopCarPresenter(this); searchShopCarPresenter.receive(uid + ""); /** * 点击结算跳转页面 */ btnMoney.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(SearchShopCarActivity.this, ConfirmActivity.class); intent.putExtra("price", allPrice.getText() + ""); startActivity(intent); } }); } private void initView() { btnMoney = findViewById(R.id.btnMoney); ex = findViewById(R.id.ex); selectAll = findViewById(R.id.selectAll); allPrice = findViewById(R.id.allPrice); count = findViewById(R.id.count); } @Override public void onSuccess(List<JsonShopCarBean.DataBean> data) { //清空一下商家店铺集合的数据 groupList.clear(); //清空一下商品集合的数据 childList.clear(); //将商家店铺大集合的数据存到另一个集合里 groupList.addAll(data); //将商品小集合的数据存到另一个集合里 for (int i = 0; i < data.size(); i++) { List<JsonShopCarBean.DataBean.ListBean> list = data.get(i).getList(); childList.add(list); } /** * 配置适配器 */ myAdapter = new MyAdapter(SearchShopCarActivity.this, groupList, childList); ex.setAdapter(myAdapter); //默认展示二级列表数据 for (int i = 0; i < data.size(); i++) { ex.expandGroup(i); } } @Override public void onFailed() { } //计算总价和总数量 @Subscribe public void onMessageEven(PriceAndCountEvent event) { allPrice.setText(event.getPrice() + ".00"); count.setText("结算(" + event.getCount() + ")"); }}
ConfirmActivity.java(立即下单)
import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast;import com.bwie.myapplication.interfaces.IConfirmPresenter;import com.bwie.myapplication.presenter.ConfirmPresenter;public class ConfirmActivity extends AppCompatActivity implements IConfirmPresenter { private String price; private String uid = "3384"; private TextView myPrice; private RelativeLayout order; private ConfirmPresenter confirmPresenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_confirm); initView();//初始化视图 Intent intent = getIntent(); price = intent.getStringExtra("price"); myPrice.setText("实付款:¥" + price); confirmPresenter = new ConfirmPresenter(this); /** * 立即下单的点击事件 */ order.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { confirmPresenter.receive(uid,price+""); } }); } //初始化视图 private void initView() { myPrice = (TextView) findViewById(R.id.myPrice); order = (RelativeLayout) findViewById(R.id.order); } @Override public void onSuccess(String msg) { if(msg.trim()=="订单创建成功"||msg.trim().equals("订单创建成功")){ Toast.makeText(ConfirmActivity.this,msg,Toast.LENGTH_SHORT).show(); Intent intent = new Intent(ConfirmActivity.this, MyOrderActivity.class); startActivity(intent); }else{ Toast.makeText(ConfirmActivity.this,msg,Toast.LENGTH_SHORT).show(); } } @Override public void onFailed() { }}
MyOrderActivity.java(订单详情页面)
import android.os.Bundle;import android.support.design.widget.TabLayout;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;public class MyOrderActivity extends AppCompatActivity { private TabLayout myTab; private ViewPager viewPage; private String[] title = {"全部", "待支付", "已支付", "已取消"}; private String[] urlTitle = {"9", "0", "1", "2"}; private MyAdapter myAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_myorder); initView();//初始化视图 myAdapter = new MyAdapter(getSupportFragmentManager()); viewPage.setAdapter(myAdapter); myTab.setupWithViewPager(viewPage); } private void initView() { myTab = (TabLayout) findViewById(R.id.myTab); viewPage = (ViewPager) findViewById(R.id.viewPage); } //内部适配器 class MyAdapter extends FragmentPagerAdapter { public MyAdapter(FragmentManager fm) { super(fm); } @Override public CharSequence getPageTitle(int position) { return title[position]; } @Override public Fragment getItem(int position) { //创建fragment对象并返回 Bundle bundle = new Bundle(); bundle.putString("url", urlTitle[position]); PayFragment payFragment = new PayFragment(); payFragment.setArguments(bundle); return payFragment; } @Override public int getCount() { return title.length; } }}
PayFragment.java
import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import com.bwie.myapplication.adapter.MyRecyclerViewAdapter;import com.bwie.myapplication.bean.JsonPayBean;import com.bwie.myapplication.interfaces.IPayPresenter;import com.bwie.myapplication.presenter.PayPresenter;import java.util.List;public class PayFragment extends Fragment implements IPayPresenter { private View view; private String uid = "3384"; private PayPresenter payPresenter; private RecyclerView recyclerView; private MyRecyclerViewAdapter myAdapter; private String urlTitle; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = View.inflate(getActivity(), R.layout.activity_pay, null); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initView();//初始化数据 Bundle bundle = getArguments(); urlTitle = bundle.getString("url").toString();// Log.i("qqqq",urlTitle); payPresenter = new PayPresenter(this);//实例化 payPresenter.receive(uid, urlTitle); } //初始化数据 private void initView() { recyclerView = view.findViewById(R.id.recyclerView); } @Override public void onSuccess(List<JsonPayBean.DataBean> data) { recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); myAdapter = new MyRecyclerViewAdapter(getActivity(), data); recyclerView.setAdapter(myAdapter); } @Override public void onFailed() { }}
Adapter
MessageEvent.java
package com.bwie.myapplication.adapter;public class MessageEvent { private boolean checkd; public boolean isCheckd() { return checkd; } public void setCheckd(boolean checkd) { this.checkd = checkd; }}
MyAdapter.java
package com.bwie.myapplication.adapter;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseExpandableListAdapter;import android.widget.Button;import android.widget.CheckBox;import android.widget.ImageView;import android.widget.TextView;import com.bwie.myapplication.R;import com.bwie.myapplication.bean.JsonShopCarBean;import com.nostra13.universalimageloader.core.ImageLoader;import org.greenrobot.eventbus.EventBus;import java.util.List;public class MyAdapter extends BaseExpandableListAdapter { private Context context;//上下文 private List<JsonShopCarBean.DataBean> groupList;//商家店铺 private List<List<JsonShopCarBean.DataBean.ListBean>> childList;//商品 public MyAdapter(Context context, List<JsonShopCarBean.DataBean> groupList, List<List<JsonShopCarBean.DataBean.ListBean>> childList) { this.context = context; this.groupList = groupList; this.childList = childList; } @Override public int getGroupCount() { return groupList.size(); } @Override public int getChildrenCount(int i) { return childList.get(i).size(); } @Override public Object getGroup(int i) { return groupList.get(i); } @Override public Object getChild(int i, int i1) { return childList.get(i).get(i1); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return false; } class ViewHolder { CheckBox checkGroup; TextView storeName; } @Override public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) { //优化 final ViewHolder holder; if (view == null) { holder = new ViewHolder(); view = View.inflate(context, R.layout.layout_group, null); holder.checkGroup = view.findViewById(R.id.checkGroup); holder.storeName = view.findViewById(R.id.storeName); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } //赋值 holder.storeName.setText(groupList.get(i).getSellerName()); //设置以及列表的点击状态 holder.checkGroup.setChecked(groupList.get(i).isChecked()); //一级列表checkBox的点击事件 holder.checkGroup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //判断一级列表复选框的状态,设置为true或false groupList.get(i).setChecked(holder.checkGroup.isChecked()); //改变二级checkBox的状态 changeChildState(i, holder.checkGroup.isChecked()); //算钱 EventBus.getDefault().post(computer()); //改变全选状态 isAllGroupCbSelect判断一级是否全部选中 changeAllState(isAllGroupSelect()); //必刷新 notifyDataSetChanged(); } }); //返回视图 return view; } class ViewHolder1 { CheckBox checkChild; ImageView img; TextView title; TextView price; TextView lessen; TextView count; TextView add; Button btnDelete; } /** * 子列表 */ @Override public View getChildView(final int i, int i1, boolean b, View view, ViewGroup viewGroup) { final ViewHolder1 holder1; final JsonShopCarBean.DataBean.ListBean listBean = childList.get(i).get(i1); if (view == null) { holder1 = new ViewHolder1(); view = View.inflate(context, R.layout.layout_child, null); holder1.checkChild = view.findViewById(R.id.checkChild); holder1.img = view.findViewById(R.id.img); holder1.title = view.findViewById(R.id.title); holder1.price = view.findViewById(R.id.price); holder1.lessen = view.findViewById(R.id.lessen); holder1.count = view.findViewById(R.id.count); holder1.add = view.findViewById(R.id.add); holder1.btnDelete = view.findViewById(R.id.btnDelete); view.setTag(holder1); } else { holder1 = (ViewHolder1) view.getTag(); } //赋值 String images = listBean.getImages(); String[] split = images.split("\\|"); ImageLoader.getInstance().displayImage(split[0], holder1.img); holder1.title.setText(listBean.getTitle()); holder1.price.setText(listBean.getPrice() + ""); holder1.count.setText(listBean.getNum() + ""); //设置二级列表checkbox的属性 holder1.checkChild.setChecked(childList.get(i).get(i1).isChecked()); //二级列表的点击事件 holder1.checkChild.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //设置该条目中的checkbox属性值 listBean.setChecked(holder1.checkChild.isChecked()); //计算价钱 PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); //判断当前checkbox是选中的状态 if (holder1.checkChild.isChecked()) { //如果全部选中(isAllChildCbSelected) if (isAllChildCbSelected(i)) { //改变一级列表的状态 changeGroupState(i, true); //改变全选的状态 changeAllState(isAllGroupSelect()); } } else { //如果没有全部选中,一级列表的checkbox为false不为选中 changeGroupState(i, false); changeAllState(isAllGroupSelect()); } notifyDataSetChanged(); } }); //加号 holder1.add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int num = listBean.getNum(); //num为int类型所以要加空字符串 holder1.count.setText(++num + ""); listBean.setNum(num); //如果二级列表的checkbox为选中,计算价钱 if (holder1.checkChild.isChecked()) { PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); } } }); //减号 holder1.lessen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int num = listBean.getNum(); if (num == 1) { return; } holder1.count.setText(--num + ""); listBean.setNum(num); if (holder1.checkChild.isChecked()) { PriceAndCountEvent priceAndCountEvent = computer(); EventBus.getDefault().post(priceAndCountEvent); } } }); return view; } @Override public boolean isChildSelectable(int i, int i1) { return false; } //改变二级列表的checkBox的状态,如果一级选中,控制二级也选中 private void changeChildState(int i, boolean flag) { List<JsonShopCarBean.DataBean.ListBean> listBeen = childList.get(i); for (int j = 0; j < listBeen.size(); j++) { JsonShopCarBean.DataBean.ListBean listBean = listBeen.get(j); listBean.setChecked(flag); } } //判断一级列表是否全部选中 public boolean isAllGroupSelect() { for (int i = 0; i < childList.size(); i++) { JsonShopCarBean.DataBean dataBean = groupList.get(i); if (!dataBean.isChecked()) { return false; } } return true; } //改变全选的状态 private void changeAllState(boolean flag) { //导入的类 MessageEvent messageEvent = new MessageEvent(); messageEvent.setCheckd(flag); EventBus.getDefault().post(messageEvent); } //改变列表的checkBox的状态 private void changeGroupState(int i, boolean flag) { JsonShopCarBean.DataBean dataBean = groupList.get(i); dataBean.setChecked(flag); } //判断二级列表是否全部选中 private boolean isAllChildCbSelected(int i) { List<JsonShopCarBean.DataBean.ListBean> listBeen = childList.get(i); for (int j = 0; j < listBeen.size(); j++) { JsonShopCarBean.DataBean.ListBean listBean = listBeen.get(j); if (!listBean.isChecked()) { return false; } } return true; } //设置全选,反选 public void changeAllListCbState(boolean flag) { for (int i = 0; i < childList.size(); i++) { changeGroupState(i, flag); changeChildState(i, flag); } //算钱 EventBus.getDefault().post(computer()); notifyDataSetChanged(); } //计算列表的价钱 private PriceAndCountEvent computer() { int count = 0; int price = 0; int to = 0; for (int i = 0; i < childList.size(); i++) { List<JsonShopCarBean.DataBean.ListBean> listBeen = childList.get(i); for (int j = 0; j < listBeen.size(); j++) { JsonShopCarBean.DataBean.ListBean listBean = listBeen.get(j); if (listBean.isChecked()) { price += listBean.getNum() * listBean.getPrice(); count += listBean.getNum(); to += listBean.getNum(); } } } PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent(); priceAndCountEvent.setCount(count); priceAndCountEvent.setPrice(price); priceAndCountEvent.setTo(to); return priceAndCountEvent; }}
MyRecyclerViewAdapter.java
package com.bwie.myapplication.adapter;import android.content.Context;import android.graphics.Color;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.TextView;import com.bwie.myapplication.R;import com.bwie.myapplication.bean.JsonPayBean;import java.util.List;public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> { private Context context; private List<JsonPayBean.DataBean> data; public MyRecyclerViewAdapter(Context context, List<JsonPayBean.DataBean> data) { this.context = context; this.data = data; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.layout_pay, parent, false); ViewHolder viewHolder = new ViewHolder(view); return viewHolder; } @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.price.setText(data.get(position).getPrice() + ""); if (data.get(position).getStatus() == 0) { holder.state.setTextColor(Color.RED); holder.state.setText("待支付"); } else if (data.get(position).getStatus() == 1) { holder.state.setTextColor(Color.BLACK); holder.state.setText("已支付"); } else if (data.get(position).getStatus() == 2) { holder.state.setTextColor(Color.BLACK); holder.state.setText("已取消"); } else { } holder.listName.setText(data.get(position).getTitle()); holder.editTime.setText("创建时间:" + data.get(position).getCreatetime()); } @Override public int getItemCount() { return data.size(); } class ViewHolder extends RecyclerView.ViewHolder { TextView listName; TextView state; TextView price; TextView editTime; Button btnCancle; public ViewHolder(View itemView) { super(itemView); listName = itemView.findViewById(R.id.listName); state = itemView.findViewById(R.id.state); price = itemView.findViewById(R.id.price); editTime = itemView.findViewById(R.id.editTime); btnCancle = itemView.findViewById(R.id.btnCancle); } }}
PriceAndCountEvent.java
package com.bwie.myapplication.adapter;public class PriceAndCountEvent { private int price; private int count; private int to; public int getPrice() { return price; } public int getCount() { return count; } public int getTo(){ return to; } public void setPrice(int price) { this.price = price; } public void setCount(int count) { this.count = count; } public void setTo(int to) { this.to = to; }}
interfaces
IAddShopCarModel.java
package com.bwie.myapplication.interfaces;public interface IAddShopCarModel { void onASuccess(String msg); void onAFailed();}
IAddShopCarPresenter.java
package com.bwie.myapplication.interfaces;public interface IAddShopCarPresenter { void onASuccess(String msg); void onAFailed();}
IConfirmModel.java
package com.bwie.myapplication.interfaces;public interface IConfirmModel { void onSuccess(String msg); void onFailed();}
IConfirmPresenter.java
package com.bwie.myapplication.interfaces;public interface IConfirmPresenter { void onSuccess(String msg); void onFailed();}
IDetailsModel.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonDetailsBean;public interface IDetailsModel { void onSuccess(JsonDetailsBean.DataBean data); void onFailed();}
IDetailsPresenter.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonDetailsBean;public interface IDetailsPresenter { void onSuccess(JsonDetailsBean.DataBean data); void onFailed();}
IPayModel.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonPayBean;import java.util.List;public interface IPayModel { void onSuccess(List<JsonPayBean.DataBean> data); void onFailed();}
IPayPresenter.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonPayBean;import java.util.List;public interface IPayPresenter { void onSuccess(List<JsonPayBean.DataBean> data); void onFailed();}
IShopCarModel.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonShopCarBean;import java.util.List;public interface IShopCarModel { void onSuccess(List<JsonShopCarBean.DataBean> data); void onFailed();}
IShopCarPresenter.java
package com.bwie.myapplication.interfaces;import com.bwie.myapplication.bean.JsonShopCarBean;import java.util.List;public interface IShopCarPresenter { void onSuccess(List<JsonShopCarBean.DataBean> data); void onFailed();}
Model
AddShopCarModel.java
package com.bwie.myapplication.model;import com.bwie.myapplication.bean.JsonAppShopCarBean;import com.bwie.myapplication.interfaces.IAddShopCarModel;import com.bwie.myapplication.utils.IOkHttpUtils;import com.bwie.myapplication.utils.OKHttpUtils;import com.google.gson.Gson;import java.util.HashMap;public class AddShopCarModel { public void receive(String uid, String pid, final IAddShopCarModel iAddShopCarModel) { OKHttpUtils instance = OKHttpUtils.getInstance(); HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("uid", uid); hashMap.put("pid", pid); instance.doGet("http://120.27.23.105/product/addCart", hashMap, new IOkHttpUtils() { @Override public void onSuccess(String str) { if (str != null) { Gson gson = new Gson(); JsonAppShopCarBean jsonAppShopCarBean = gson.fromJson(str, JsonAppShopCarBean.class); if (jsonAppShopCarBean != null) { String msg = jsonAppShopCarBean.getMsg(); iAddShopCarModel.onASuccess(msg); } } } @Override public void onFailed(String message) { iAddShopCarModel.onAFailed(); } }); }}
ConfirmModel.java
package com.bwie.myapplication.model;import com.bwie.myapplication.bean.JsonConfirmBean;import com.bwie.myapplication.interfaces.IConfirmModel;import com.bwie.myapplication.utils.IOkHttpUtils;import com.bwie.myapplication.utils.OKHttpUtils;import com.google.gson.Gson;import java.util.HashMap;public class ConfirmModel { public void receive(String uid, String price, final IConfirmModel iConfirmModel) { OKHttpUtils instance = OKHttpUtils.getInstance(); HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("uid", uid); hashMap.put("price", price); instance.doGet("http://120.27.23.105/product/createOrder", hashMap, new IOkHttpUtils() { @Override public void onSuccess(String str) { if (str != null) { Gson gson = new Gson(); JsonConfirmBean jsonConfirmBean = gson.fromJson(str, JsonConfirmBean.class); if (jsonConfirmBean != null) { String msg = jsonConfirmBean.getMsg(); if (msg != null) { iConfirmModel.onSuccess(msg); } } } } @Override public void onFailed(String message) { iConfirmModel.onFailed(); } }); }}
DetailsModel.java
package com.bwie.myapplication.model;import com.bwie.myapplication.bean.JsonDetailsBean;import com.bwie.myapplication.interfaces.IDetailsModel;import com.bwie.myapplication.utils.IOkHttpUtils;import com.bwie.myapplication.utils.OKHttpUtils;import com.google.gson.Gson;import java.util.HashMap;public class DetailsModel { public void receive(String pid, final IDetailsModel iDetailsModel){ OKHttpUtils instance = OKHttpUtils.getInstance(); HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("pid",pid); instance.doGet("http://120.27.23.105/product/getProductDetail", hashMap, new IOkHttpUtils() { @Override public void onSuccess(String str) { if(str!=null){ Gson gson = new Gson(); JsonDetailsBean jsonDetailsBean = gson.fromJson(str, JsonDetailsBean.class); if(jsonDetailsBean!=null){ JsonDetailsBean.DataBean data = jsonDetailsBean.getData(); iDetailsModel.onSuccess(data); } } } @Override public void onFailed(String message) { } }); }}
PayModel.java
package com.bwie.myapplication.model;import com.bwie.myapplication.bean.JsonPayBean;import com.bwie.myapplication.interfaces.IPayModel;import com.bwie.myapplication.utils.IOkHttpUtils;import com.bwie.myapplication.utils.OKHttpUtils;import com.google.gson.Gson;import java.util.HashMap;import java.util.List;public class PayModel { public void receive(String uid, String urlTitle, final IPayModel iPayModel) { OKHttpUtils instance = OKHttpUtils.getInstance(); HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("uid", uid); if(urlTitle.trim().equals("9")){ }else{ hashMap.put("status",urlTitle); } instance.doGet("http://120.27.23.105/product/getOrders", hashMap, new IOkHttpUtils() { @Override public void onSuccess(String str) { if (str != null) { Gson gson = new Gson(); JsonPayBean jsonPayBean = gson.fromJson(str, JsonPayBean.class); if (jsonPayBean != null) { List<JsonPayBean.DataBean> data = jsonPayBean.getData(); if (data != null) { iPayModel.onSuccess(data); } } } } @Override public void onFailed(String message) { iPayModel.onFailed(); } }); }}
SearchShopCarModel.java
package com.bwie.myapplication.model;import com.bwie.myapplication.bean.JsonShopCarBean;import com.bwie.myapplication.interfaces.IShopCarModel;import com.bwie.myapplication.utils.IOkHttpUtils;import com.bwie.myapplication.utils.OKHttpUtils;import com.google.gson.Gson;import java.util.HashMap;import java.util.List;public class SearchShopCarModel { public void receive(String uid, final IShopCarModel iShopCarModel) { OKHttpUtils instance = OKHttpUtils.getInstance(); HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("uid", uid); instance.doGet("http://120.27.23.105/product/getCarts", hashMap, new IOkHttpUtils() { @Override public void onSuccess(String str) { if (str != null) { Gson gson = new Gson(); JsonShopCarBean jsonShopCarBean = gson.fromJson(str, JsonShopCarBean.class); if (jsonShopCarBean != null) { List<JsonShopCarBean.DataBean> data = jsonShopCarBean.getData(); iShopCarModel.onSuccess(data); } } } @Override public void onFailed(String message) { iShopCarModel.onFailed(); } }); }}
Presenter
AddShopCarPresenter.java
package com.bwie.myapplication.presenter;import com.bwie.myapplication.interfaces.IAddShopCarModel;import com.bwie.myapplication.interfaces.IAddShopCarPresenter;import com.bwie.myapplication.model.AddShopCarModel;public class AddShopCarPresenter implements IAddShopCarModel { private AddShopCarModel addShopCarModel; private IAddShopCarPresenter iAddShopCarPresenter; public AddShopCarPresenter(IAddShopCarPresenter iAddShopCarPresenter) { this.iAddShopCarPresenter = iAddShopCarPresenter; addShopCarModel = new AddShopCarModel(); } public void receive(String uid, String pid){ addShopCarModel.receive(uid,pid,this); } @Override public void onASuccess(String msg) { iAddShopCarPresenter.onASuccess(msg); } @Override public void onAFailed() { iAddShopCarPresenter.onAFailed(); }}
ConfirmPresenter.java
package com.bwie.myapplication.presenter;import com.bwie.myapplication.interfaces.IConfirmModel;import com.bwie.myapplication.interfaces.IConfirmPresenter;import com.bwie.myapplication.model.ConfirmModel;public class ConfirmPresenter implements IConfirmModel { private ConfirmModel confirmModel; private IConfirmPresenter iConfirmPresenter; public ConfirmPresenter(IConfirmPresenter iConfirmPresenter) { this.iConfirmPresenter = iConfirmPresenter; confirmModel = new ConfirmModel(); } public void receive(String uid, String price) { confirmModel.receive(uid, price, this); } @Override public void onSuccess(String msg) { iConfirmPresenter.onSuccess(msg); } @Override public void onFailed() { iConfirmPresenter.onFailed(); }}
DetailsPresenter.java
package com.bwie.myapplication.presenter;import com.bwie.myapplication.bean.JsonDetailsBean;import com.bwie.myapplication.interfaces.IDetailsModel;import com.bwie.myapplication.interfaces.IDetailsPresenter;import com.bwie.myapplication.model.DetailsModel;public class DetailsPresenter implements IDetailsModel { private DetailsModel detailsModel; private IDetailsPresenter iDetailsPresenter; public DetailsPresenter(IDetailsPresenter iDetailsPresenter) { this.iDetailsPresenter = iDetailsPresenter; detailsModel = new DetailsModel(); } public void receive(String pid){ detailsModel.receive(pid,this); } @Override public void onSuccess(JsonDetailsBean.DataBean data) { iDetailsPresenter.onSuccess(data); } @Override public void onFailed() { iDetailsPresenter.onFailed(); }}
PayPresenter.java
package com.bwie.myapplication.presenter;import com.bwie.myapplication.bean.JsonPayBean;import com.bwie.myapplication.interfaces.IPayModel;import com.bwie.myapplication.interfaces.IPayPresenter;import com.bwie.myapplication.model.PayModel;import java.util.List;public class PayPresenter implements IPayModel { private PayModel payModel; private IPayPresenter iPayPresenter; public PayPresenter(IPayPresenter iPayPresenter) { this.iPayPresenter = iPayPresenter; payModel = new PayModel(); } public void receive(String uid,String urlTitle) { payModel.receive(uid,urlTitle, this); } @Override public void onSuccess(List<JsonPayBean.DataBean> data) { iPayPresenter.onSuccess(data); } @Override public void onFailed() { iPayPresenter.onFailed(); }}
SearchShopCarPresenter.java
package com.bwie.myapplication.presenter;import com.bwie.myapplication.bean.JsonShopCarBean;import com.bwie.myapplication.interfaces.IShopCarModel;import com.bwie.myapplication.interfaces.IShopCarPresenter;import com.bwie.myapplication.model.SearchShopCarModel;import java.util.List;public class SearchShopCarPresenter implements IShopCarModel { private SearchShopCarModel searchShopCarModel; private IShopCarPresenter iShopCarPresenter; public SearchShopCarPresenter(IShopCarPresenter iShopCarPresenter) { this.iShopCarPresenter = iShopCarPresenter; searchShopCarModel = new SearchShopCarModel(); } public void receive(String uid) { searchShopCarModel.receive(uid, this); } @Override public void onSuccess(List<JsonShopCarBean.DataBean> data) { iShopCarPresenter.onSuccess(data); } @Override public void onFailed() { iShopCarPresenter.onFailed(); }}
Utils
Intercept.java
package com.bwie.myapplication.utils;import java.io.IOException;import okhttp3.HttpUrl;import okhttp3.Interceptor;import okhttp3.Request;import okhttp3.Response;public class Intercept implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); HttpUrl url=original.url().newBuilder() .addQueryParameter("source","android") .build(); //添加请求头 Request request = original.newBuilder() .url(url) .build(); return chain.proceed(request); }}
IOkHttpUtils.java
package com.bwie.myapplication.utils;public interface IOkHttpUtils { void onSuccess(String str); void onFailed(String message);}
OKHttpUtils.java
package com.bwie.myapplication.utils;import android.os.Handler;import android.util.Log;import java.io.IOException;import java.util.Map;import okhttp3.Call;import okhttp3.Callback;import okhttp3.OkHttpClient;import okhttp3.Request;import okhttp3.Response;public class OKHttpUtils { private static OKHttpUtils okHttpUtils; private static Handler handler = new Handler(); //私有化构造方法 public OKHttpUtils() { } /** * 获取OKhttpClient实例化 */ public static OKHttpUtils getInstance() { if (null == okHttpUtils) { synchronized (OKHttpUtils.class) { if (null == okHttpUtils) { okHttpUtils = new OKHttpUtils(); } } } return okHttpUtils; } /** * 封装的异步Get请求 */ public void doGet(String path, Map<String, String> map, final IOkHttpUtils okHttpCallBack) { //创建一个字符串容器 StringBuilder sb = null; if (map.size() == 0) { if (null == sb) { sb = new StringBuilder(); sb.append(path); } } else { for (String key : map.keySet()) { if (null == sb) { sb = new StringBuilder(); sb.append(path); sb.append("?"); } else { sb.append("&"); } sb.append(key).append("=").append(map.get(key)); } } //System.out.println("分类 : "+path + sb.toString()); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(new Intercept())//使用拦截器 .build(); Request request = new Request.Builder() .url(sb.toString()) .get() .build(); //OKHttp 网络 Call call = okHttpClient.newCall(request); //异步请求 call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { //请求失败 Log.e("SKN", "OK请求失败"); okHttpCallBack.onFailed(e.getMessage()); } @Override public void onResponse(Call call, final Response response) throws IOException { final String str = response.body().string(); //请求成功 handler.post(new Runnable() { @Override public void run() { Log.e("WWWW", "请求成功" + str); okHttpCallBack.onSuccess(str); } }); } }); }}
布局文件
activity_confirm.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#787878" tools:context="com.bwie.myapplication.ConfirmActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#FF0"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="确认订单" android:textColor="#000" android:textSize="22sp" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:background="#FFF"> <TextView android:id="@+id/myPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="价格" android:textColor="#F00" android:textSize="22sp" /> <RelativeLayout android:id="@+id/order" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/myPrice" android:background="#F00"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="立即下单" android:textColor="#FFF" android:textSize="22sp" /> </RelativeLayout> </RelativeLayout></RelativeLayout>
activity_details.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.myapplication.DetailsActivity"> <ImageView android:id="@+id/img" android:layout_width="match_parent" android:layout_height="250dp" android:src="@mipmap/ic_launcher" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/img" android:text="标题" android:textSize="24sp" /> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/title" android:text="价格" android:textColor="#F00" android:textSize="18sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:orientation="horizontal"> <Button android:id="@+id/btnShopCar" android:layout_width="0dp" android:layout_height="80dp" android:layout_weight="1" android:text="购物车" android:textSize="24sp" /> <Button android:id="@+id/btnJoin" android:layout_width="0dp" android:layout_height="80dp" android:layout_weight="1" android:text="加入购物车" android:textSize="24sp" /> </LinearLayout></RelativeLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwie.myapplication.SplashActivity"> <ImageView android:layout_centerHorizontal="true" android:id="@+id/img" android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/ic_launcher_round" /></RelativeLayout>
activity_myorder.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#7878" tools:context="com.bwie.myapplication.MyOrderActivity"> <RelativeLayout android:id="@+id/top" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="订单列表" android:textColor="#000" android:textSize="22sp" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/top" android:background="#787878" /> <android.support.design.widget.TabLayout android:id="@+id/myTab" android:layout_width="match_parent" android:layout_height="50dp" android:layout_below="@id/top" android:layout_marginTop="10dp" app:tabGravity="fill" app:tabIndicatorColor="@color/colorAccent" app:tabMode="fixed" app:tabSelectedTextColor="@color/colorPrimaryDark" app:tabTextColor="@color/colorPrimary"></android.support.design.widget.TabLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@id/myTab" android:background="#787878" /> <android.support.v4.view.ViewPager android:id="@+id/viewPage" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/myTab" android:layout_marginTop="10dp"></android.support.v4.view.ViewPager></RelativeLayout>
activity_pay.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:background="#EBEBEB" android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView></RelativeLayout>
activity_search.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.bwie.myapplication.SearchShopCarActivity"> <ExpandableListView android:id="@+id/ex" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent"></ExpandableListView> <!--底部视图--> <RelativeLayout android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" android:background="#F00"> <CheckBox android:id="@+id/selectAll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/selectAll" android:text="全选" android:textColor="#000" android:textSize="18sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="80dp" android:layout_toRightOf="@id/selectAll" android:text="总价:" android:textColor="#000" android:textSize="18sp" /> <TextView android:id="@+id/allPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="130dp" android:layout_toRightOf="@id/selectAll" android:text="0.0" android:textColor="#000" android:textSize="18sp" /> <RelativeLayout android:id="@+id/btnMoney" android:layout_width="120dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:background="#FF0"> <TextView android:id="@+id/count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="结算" android:textColor="#000" android:textSize="18sp" /> </RelativeLayout> </RelativeLayout></LinearLayout>
layout_child.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <CheckBox android:id="@+id/checkChild" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:scaleX="0.6" android:scaleY="0.6" /> <ImageView android:id="@+id/img" android:layout_width="70dp" android:layout_height="80dp" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/checkChild" android:background="@mipmap/ic_launcher" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="15dp" android:layout_toRightOf="@id/img" android:orientation="vertical"> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="酒红色纯红色纯羊毛西服套装" android:textColor="@android:color/black" android:textSize="12sp" android:textStyle="bold" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:orientation="horizontal"> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥390" android:textColor="@android:color/holo_red_dark" android:textSize="12sp" android:textStyle="bold" /> <LinearLayout android:id="@+id/rl_edit" android:layout_width="120dp" android:layout_height="30dp" android:layout_marginLeft="50dp" android:background="@android:color/holo_orange_light"> <TextView android:id="@+id/lessen" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@android:color/white" android:gravity="center" android:text=" - " android:textColor="@android:color/black" /> <TextView android:id="@+id/count" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@android:color/white" android:gravity="center" android:text="1" /> <TextView android:id="@+id/add" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@android:color/white" android:gravity="center" android:text=" + " /> </LinearLayout> </LinearLayout> </LinearLayout> <Button android:id="@+id/btnDelete" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="5dp" android:background="@android:color/holo_blue_light" android:gravity="center" android:text="x" android:textColor="@android:color/holo_green_dark" android:textSize="20sp" android:visibility="visible" /></RelativeLayout>
layout_group.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <CheckBox android:id="@+id/checkGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" /> <TextView android:id="@+id/storeName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:layout_toRightOf="@id/checkGroup" android:text="淘宝店铺名称" android:textColor="#000" android:textSize="20dp" /></RelativeLayout>
layout_pay.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#EBEBEB" android:orientation="vertical"> <LinearLayout android:background="#FFF" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/listName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:text="订单列表测试名单" /> <TextView android:id="@+id/state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="20dp" android:text="未支付" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:text="价格" android:textColor="#F00" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <TextView android:id="@+id/editTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="20dp" android:text="创建时间" /> <Button android:id="@+id/btnCancle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="20dp" android:text="取消订单" /> </RelativeLayout> </LinearLayout></LinearLayout>
以上代码仅供参考
- 利用MVP实现购物车提交订单
- MVP实现购物车与订单
- MVP二级购物车和订单
- 购物车到订单的MVP方法
- angularJS实现购物车订单
- mvc购物车项目--提交订单并创建订单
- MVP实现购物车功能
- MVP实现二级购物车
- MVP实现二级购物车
- magento 提交订单失败跳回到购物车的问题
- mvp二级购物车的实现
- MVP+Retrofit实现二级购物车
- RxJava+Retrofit+Mvp实现购物车
- Rxjava+Retrofit+MVP实现购物车Mode
- asp.net购物车,订单以及模拟支付宝支付(三)---提交订单
- 购物车/订单
- 购物车和订单
- 购物车+订单
- 做了8年游戏开发的程序员对未来的忧虑
- pl/sql通过修改配置文件的方式实现数据库的连接
- 竞价单页小程序,适合在公众号,朋友圈投放竞价的小程序
- c++初始化列表
- 趣图丨改BUG的日常
- 利用MVP实现购物车提交订单
- SylixOS中Proc文件系统简介
- JAVA总结(流程控制1--分支语句)
- 订单详情的fragment
- 仿京东购物车
- 配置Mysql Group Replication遇到的问题笔记
- js 参数传递方式:按值传递
- 标准 (ANSI C, POSIX, SVID, XPG, ...)
- mongodb php之limit查询技巧