DingDanStatusActivity
package bwie.com.a20180113zhoulian.view.activity; import android.os.Bundle; import android.support.annotation.IdRes; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.FrameLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.view.fragment.DaiZhiFuFragment; import bwie.com.a20180113zhoulian.view.fragment.YiQuXiaoFragment; import bwie.com.a20180113zhoulian.view.fragment.YiZhiFuFragment; public class DingDanStatusActivity extends AppCompatActivity { private RadioButton rb1; private RadioButton rb2; private RadioButton rb3; private RadioGroup rg; private FrameLayout fl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ding_dan_status); initView(); getSupportFragmentManager().beginTransaction().replace(R.id.fl,new DaiZhiFuFragment()).commit(); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { switch (checkedId) { case R.id.rb1: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new DaiZhiFuFragment()).commit(); break; case R.id.rb2: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new YiZhiFuFragment()).commit(); break; case R.id.rb3: getSupportFragmentManager().beginTransaction().replace(R.id.fl, new YiQuXiaoFragment()).commit(); break; } } }); } public void onViewClicked(View view) { } private void initView() { rb1 = (RadioButton) findViewById(R.id.rb1); rb2 = (RadioButton) findViewById(R.id.rb2); rb3 = (RadioButton) findViewById(R.id.rb3); rg = (RadioGroup) findViewById(R.id.rg); fl = (FrameLayout) findViewById(R.id.fl); } }
DaiZhiFuAdapter
package bwie.com.changteng20171221.view.adapter; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.os.Handler; import android.os.Message; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.changteng20171221.R; import bwie.com.changteng20171221.model.bean.DingDanBean; import bwie.com.changteng20171221.utils.CommonUtil; import bwie.com.changteng20171221.utils.OkHttpUtil; import bwie.com.changteng20171221.view.horder.ShuHorder; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by dell on 2017/12/21. */ public class DaiZhiFuAdapter extends RecyclerView.Adapter<ShuHorder> { private Handler handler; private List<DingDanBean.DataBean> list; private Context context; public DaiZhiFuAdapter(Context context, List<DingDanBean.DataBean> list, Handler handler) { this.context = context; this.list = list; this.handler=handler; } //....回想listView的优化,,,1.创建viewHolder....2.与条目的视图进行绑定的 //onCreateViewHolder...创建一个ViewHolder....根据条目的视图创建自己的holder对象 @Override public ShuHorder onCreateViewHolder(ViewGroup parent, int viewType) { //inflater...条目的视图 View view = LayoutInflater.from(context).inflate(R.layout.item_text_layout, parent, false); ShuHorder holder = new ShuHorder(view); return holder; } /** * onBindViewHolder 绑定上viewHolder之后的操作...主要是赋值(textView,button,checkBox...)的操作 * @param holder */ @Override public void onBindViewHolder(ShuHorder holder, final int i) { holder.textView.setText(list.get(i).getTitle()+"订单号为:"+list.get(i).getOrderid()); holder.text_time.setText(list.get(i).getCreatetime()); holder.price.setText(list.get(i).getPrice()+""); holder.status.setTextColor(Color.RED); holder.status.setText("待支付"); holder.btn.setText("取消订单"); holder.btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> pramas=new HashMap<String, String>(); pramas.put("uid",4084+""); pramas.put("status",2+""); pramas.put("orderId",list.get(i).getOrderid()+""); Log.d("AAAAAA",list.get(i).getOrderid()+""); OkHttpUtil.doPost("https://www.zhaoapi.cn/product/updateOrder", pramas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { CommonUtil.runOnUIThread(new Runnable() { @Override public void run() { // 通过AlertDialog.Builder这个类来实例化我们的一个AlertDialog的对象 AlertDialog.Builder builder = new AlertDialog.Builder(context); // 设置Title的内容 builder.setTitle("提示"); // 设置Content来显示一个信息 builder.setMessage("确定取消订单吗?"); // 设置一个PositiveButton builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Message msg= Message.obtain(); msg.arg1=list.get(i).getStatus(); msg.what=1; handler.sendMessage(msg); } }); // 设置一个NegativeButton builder.setNegativeButton("取消",null); builder.show(); } }); } }); } }); } /** * 条目的数量 * @return */ @Override public int getItemCount() { return list.size(); } }
MyAdapter
package bwie.com.a20180113zhoulian.view.adapter; import android.content.Context; import android.net.Uri; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.ChaXunBean; import bwie.com.a20180113zhoulian.model.bean.CountPriceBean; import bwie.com.a20180113zhoulian.presenter.MyPresenter; import bwie.com.a20180113zhoulian.utils.ApiUtil; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; /** * Created by dell on 2018/1/17. */ public class MyAdapter extends BaseExpandableListAdapter{ private RelativeLayout relative_progress; private MyPresenter cartPresenter; private Handler handler; private ChaXunBean cartBean; private Context context; private int size; private int childI; private int allSize; private int index; private List<Integer> listpid=null; public MyAdapter(Context context, ChaXunBean cartBean, Handler handler, MyPresenter cartPresenter, RelativeLayout relative_progress) { this.context = context; this.cartBean = cartBean; this.handler = handler; this.cartPresenter = cartPresenter; this.relative_progress = relative_progress; } @Override public int getGroupCount() { return cartBean.getData().size(); } @Override public int getChildrenCount(int groupPosition) { return cartBean.getData().get(groupPosition).getList().size(); } @Override public Object getGroup(int groupPosition) { return cartBean.getData().get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return cartBean.getData().get(groupPosition).getList().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) { final GroupHolder holder; if (view == null){ view = View.inflate(context, R.layout.group_item_layout,null); holder = new GroupHolder(); holder.check_group = view.findViewById(R.id.check_group); holder.text_group = view.findViewById(R.id.text_group); view.setTag(holder); }else { holder = (GroupHolder) view.getTag(); } final ChaXunBean.DataBean dataBean = cartBean.getData().get(groupPosition); //赋值 holder.check_group.setChecked(dataBean.isGroupChecked()); holder.text_group.setText(dataBean.getSellerName()); //组的点击事件...也要去请求更新的接口 holder.check_group.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { relative_progress.setVisibility(View.VISIBLE);//显示 size = dataBean.getList().size(); childI = 0; updateAllInGroup(holder.check_group.isChecked(),dataBean); } }); return view; } /** * 更新一组的状态 * @param checked * @param dataBean */ private void updateAllInGroup(final boolean checked, final ChaXunBean.DataBean dataBean) { ChaXunBean.DataBean.ListBean listBean = dataBean.getList().get(childI);//0 //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","11824"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected()==0 ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); RetrofitFactory.get("https://www.zhaoapi.cn/product/updateCarts",params).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { if (result.toString()!=null){ childI = childI+1;//0,1,2...3 if (childI <size){ updateAllInGroup(checked,dataBean); }else { //所有的条目已经更新完成....再次请求查询购物车的数据 cartPresenter.getPUser(ApiUtil.cartUrl); } } } @Override public void onFailed() { } }); } @Override public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) { ChildHolder holder; if (view == null){ view = View.inflate(context, R.layout.child_item_layout,null); holder = new ChildHolder(); holder.text_add = view.findViewById(R.id.text_add); holder.text_num = view.findViewById(R.id.text_num); holder.text_jian = view.findViewById(R.id.text_jian); holder.text_title = view.findViewById(R.id.text_title); holder.text_price = view.findViewById(R.id.text_price); holder.image_good = view.findViewById(R.id.image_good); holder.check_child = view.findViewById(R.id.check_child); holder.text_delete = view.findViewById(R.id.text_delete); view.setTag(holder); }else { holder = (ChildHolder) view.getTag(); } //赋值 final ChaXunBean.DataBean.ListBean listBean = cartBean.getData().get(groupPosition).getList().get(childPosition); holder.text_num.setText(listBean.getNum()+"");//......注意 holder.text_price.setText("¥"+listBean.getBargainPrice()); holder.text_title.setText(listBean.getTitle()); //listBean.getSelected().....0false,,,1true //设置checkBox选中状态 holder.check_child.setChecked(listBean.getSelected()==0? false:true); /*implementation 'com.github.bumptech.glide:glide:4.4.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'*/ holder.image_good.setImageURI(Uri.parse(listBean.getImages().split("\\|")[0])); holder.text_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> params=new HashMap<String, String>(); params.put("uid",11824+""); params.put("pid",listBean.getPid()+""); params.put("source","android"); RetrofitFactory.get("https://www.zhaoapi.cn/product/deleteCart", params).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { if(""!=result) { Message msg= Message.obtain(); msg.what=2; handler.sendMessage(msg); } } @Override public void onFailed() { } }); } }); //点击事件 holder.check_child.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //点击的时候 更新当前条目选中的状态,,,更新完之后,请求查询购物车,重新展示数据 updateChildChecked(listBean); } }); //加号 holder.text_add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //请求更新的接口 updateChildNum(listBean,true); } }); //减号 holder.text_jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (listBean.getNum() == 1){ Toast.makeText(context,"用户最小数量为1",Toast.LENGTH_SHORT).show(); return; } //更新数量,,,减 updateChildNum(listBean,false); } }); return view; } /** * 更新数量 * @param listBean * @param */ private void updateChildNum(ChaXunBean.DataBean.ListBean listBean, boolean isAdded) { //一旦执行更新的操作,,,progressBar显示 relative_progress.setVisibility(View.VISIBLE); //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","11824"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected())); if (isAdded){ params.put("num", String.valueOf(listBean.getNum() + 1)); }else { params.put("num", String.valueOf(listBean.getNum() - 1)); } RetrofitFactory.get(ApiUtil.updateCartUrl, params).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { if(""!=result) { cartPresenter.getPUser(ApiUtil.cartUrl); } } @Override public void onFailed() { } }); } /** * 更新子条目 网络上的状态 * @param listBean */ private void updateChildChecked(ChaXunBean.DataBean.ListBean listBean) { //一旦执行更新的操作,,,progressBar显示 relative_progress.setVisibility(View.VISIBLE); //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","11824"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected() == 0? 1:0)); params.put("num", String.valueOf(listBean.getNum())); RetrofitFactory.get(ApiUtil.updateCartUrl, params).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { if(""!=result) { cartPresenter.getPUser(ApiUtil.cartUrl); } } @Override public void onFailed() { } }); } @Override public boolean isChildSelectable(int i, int i1) { return true; } /** * 计算价格和数量 并发送显示 */ public void sendPriceAndCount() { listpid = new ArrayList<>(); double price = 0; int count = 0; //通过判断二级列表是否勾选,,,,计算价格数量 for (int i=0;i<cartBean.getData().size();i++){ for (int j = 0;j<cartBean.getData().get(i).getList().size();j++){ if (cartBean.getData().get(i).getList().get(j).getSelected() == 1){ //价格是打折的价格........... price += cartBean.getData().get(i).getList().get(j).getNum() * cartBean.getData().get(i).getList().get(j).getBargainPrice(); count += cartBean.getData().get(i).getList().get(j).getNum(); listpid.add( cartBean.getData().get(i).getList().get(j).getPid()); } } } //精准的保留double的两位小数 DecimalFormat decimalFormat = new DecimalFormat("#.00"); String priceString = decimalFormat.format(price); CountPriceBean countPriceBean = new CountPriceBean(priceString, count,listpid); //发送...显示 Message msg = Message.obtain(); msg.what = 0; msg.obj = countPriceBean; handler.sendMessage(msg); } /** * 根据全选的状态,,,,跟新每一个子条目的状态,,,全部更新完成后,查询购物车的数据进行展示 * @param checked */ public void setAllChildState(boolean checked) { //创建一个集合 装所有的子条目 List<ChaXunBean.DataBean.ListBean> allList = new ArrayList<>(); for (int i=0;i<cartBean.getData().size();i++){ for (int j=0;j<cartBean.getData().get(i).getList().size();j++){ allList.add(cartBean.getData().get(i).getList().get(j)); } } relative_progress.setVisibility(View.VISIBLE); allSize = allList.size(); index = 0; //通过 递归 更新所有子条目的选中 updateAllChild(allList,checked); } /** * 根据全选 跟新所有的子条目 * @param allList * @param checked */ private void updateAllChild(final List<ChaXunBean.DataBean.ListBean> allList, final boolean checked) { ChaXunBean.DataBean.ListBean listBean = allList.get(index);//0 //跟新的操作 //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","11824"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); RetrofitFactory.get(ApiUtil.updateCartUrl, params).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { if(""!=result) { index = index +1;//0,1,2......3 if (index < allSize){ updateAllChild(allList,checked); }else { //查询购物车 cartPresenter.getPUser(ApiUtil.cartUrl); } } } @Override public void onFailed() { } }); } private class GroupHolder{ CheckBox check_group; TextView text_group; } private class ChildHolder{ CheckBox check_child; ImageView image_good; TextView text_title; TextView text_price; TextView text_jian; TextView text_num; TextView text_add; TextView text_delete; } }
YiQuXiaoFuAdapter
package bwie.com.a20180113zhoulian.view.adapter; import android.content.Context; import android.graphics.Color; import android.os.Handler; import android.os.Message; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.DingDanBean; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; import bwie.com.a20180113zhoulian.view.horder.FraHorder; /** * Created by dell on 2017/12/21. */ public class YiQuXiaoFuAdapter extends RecyclerView.Adapter<FraHorder> { private Handler handler; private List<DingDanBean.DataBean> list; private Context context; public YiQuXiaoFuAdapter(Context context, List<DingDanBean.DataBean> list, Handler handler) { this.context = context; this.list = list; this.handler=handler; } //....回想listView的优化,,,1.创建viewHolder....2.与条目的视图进行绑定的 //onCreateViewHolder...创建一个ViewHolder....根据条目的视图创建自己的holder对象 @Override public FraHorder onCreateViewHolder(ViewGroup parent, int viewType) { //inflater...条目的视图 View view = LayoutInflater.from(context).inflate(R.layout.item_text_layout, parent, false); FraHorder holder = new FraHorder(view); return holder; } /** * onBindViewHolder 绑定上viewHolder之后的操作...主要是赋值(textView,button,checkBox...)的操作 * @param holder */ @Override public void onBindViewHolder(FraHorder holder, final int i) { holder.textView.setText(list.get(i).getTitle()+"订单号为:"+list.get(i).getOrderid()); holder.text_time.setText(list.get(i).getCreatetime()); holder.price.setText(list.get(i).getPrice()+""); holder.status.setTextColor(Color.RED); holder.status.setText("已取消"); holder.btn.setText("查看订单"); holder.btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> pramas=new HashMap<String, String>(); pramas.put("uid",11824+""); pramas.put("status",2+""); pramas.put("orderId",list.get(i).getOrderid()+""); RetrofitFactory.post("https://www.zhaoapi.cn/product/updateOrder",pramas).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { Message msg= Message.obtain(); msg.arg1=list.get(i).getStatus(); msg.what=1; handler.sendMessage(msg); } @Override public void onFailed() { } }); } }); } /** * 条目的数量 * @return */ @Override public int getItemCount() { return list.size(); } }
YiZhiFuAdapter
package bwie.com.a20180113zhoulian.view.adapter; import android.content.Context; import android.graphics.Color; import android.os.Handler; import android.os.Message; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.YiZhiFuBean; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; import bwie.com.a20180113zhoulian.view.horder.FraHorder; /** * Created by dell on 2017/12/21. */ public class YiZhiFuAdapter extends RecyclerView.Adapter<FraHorder> { private Handler handler; private List<YiZhiFuBean.DataBean> list; private Context context; public YiZhiFuAdapter(Context context, List<YiZhiFuBean.DataBean> list, Handler handler) { this.context = context; this.list = list; this.handler=handler; } //....回想listView的优化,,,1.创建viewHolder....2.与条目的视图进行绑定的 //onCreateViewHolder...创建一个ViewHolder....根据条目的视图创建自己的holder对象 @Override public FraHorder onCreateViewHolder(ViewGroup parent, int viewType) { //inflater...条目的视图 View view = LayoutInflater.from(context).inflate(R.layout.yi_item, parent, false); FraHorder holder = new FraHorder(view); return holder; } /** * onBindViewHolder 绑定上viewHolder之后的操作...主要是赋值(textView,button,checkBox...)的操作 * @param holder */ @Override public void onBindViewHolder(FraHorder holder, final int i) { holder.textView.setText(list.get(i).getTitle()+"订单号为:"+list.get(i).getOrderid()); holder.text_time.setText(list.get(i).getCreatetime()); holder.price.setText(list.get(i).getPrice()+""); holder.status.setTextColor(Color.RED); holder.status.setText("已支付"); holder.btn.setText("查看订单"); holder.btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> pramas=new HashMap<String, String>(); pramas.put("uid",11824+""); pramas.put("status",2+""); pramas.put("orderId",list.get(i).getOrderid()+""); Log.d("AAAAAA",list.get(i).getOrderid()+""); RetrofitFactory.post("https://www.zhaoapi.cn/product/updateOrder",pramas).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { Message msg= Message.obtain(); msg.arg1=list.get(i).getStatus(); msg.what=1; handler.sendMessage(msg); } @Override public void onFailed() { } }); } }); } /** * 条目的数量 * @return */ @Override public int getItemCount() { return list.size(); } }
DaiZhiFuFragment
package bwie.com.a20180113zhoulian.view.fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; 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 android.widget.Toast; import com.google.gson.Gson; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.DingDanBean; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; import bwie.com.a20180113zhoulian.view.adapter.DaiZhiFuAdapter; /** * Created by dell on 2017/12/21. */ public class DaiZhiFuFragment extends Fragment { private RecyclerView rv; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if(msg.what==1) { Toast.makeText(getActivity(),"取消成功~",Toast.LENGTH_SHORT).show(); huqushuju(); } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.daizhuce_layout, container, false); rv = view.findViewById(R.id.rv); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); huqushuju(); } private void huqushuju() { Map<String, String> prams=new HashMap<>(); prams.put("uid",11824+""); prams.put("status",0+""); prams.put("source","android"); RetrofitFactory.post("https://www.zhaoapi.cn/product/getOrders",prams).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { DingDanBean dingDanBean = new Gson().fromJson(result, DingDanBean.class); if (dingDanBean.getMsg().equals("请求成功")) { List<DingDanBean.DataBean> data = dingDanBean.getData(); if(data.size()>0) { rv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false)); //设置适配器 DaiZhiFuAdapter simpleRecycleAdapter = new DaiZhiFuAdapter(getActivity(),data,handler); rv.setAdapter(simpleRecycleAdapter); }else { Toast.makeText(getActivity(),"待支付为空",Toast.LENGTH_SHORT).show(); } } } @Override public void onFailed() { } }); } }
YiQuXiaoFragment
package bwie.com.a20180113zhoulian.view.fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; 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 android.widget.Toast; import com.google.gson.Gson; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.DingDanBean; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; import bwie.com.a20180113zhoulian.view.adapter.YiQuXiaoFuAdapter; /** * Created by dell on 2017/12/21. */ public class YiQuXiaoFragment extends Fragment { private RecyclerView rv; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if(msg.what==1) { Toast.makeText(getActivity(),"查看订单~",Toast.LENGTH_SHORT).show(); huqushuju(); } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.yiquxiao_layout, container, false); rv = view.findViewById(R.id.rv); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); huqushuju(); } private void huqushuju() { Map<String, String> prams=new HashMap<>(); prams.put("uid",11824+""); prams.put("status",2+""); prams.put("source","android"); RetrofitFactory.post("https://www.zhaoapi.cn/product/getOrders",prams).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { DingDanBean dingDanBean = new Gson().fromJson(result, DingDanBean.class); if (dingDanBean.getMsg().equals("请求成功")) { List<DingDanBean.DataBean> data = dingDanBean.getData(); if(data.size()>0) { rv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false)); //设置适配器 YiQuXiaoFuAdapter simpleRecycleAdapter = new YiQuXiaoFuAdapter(getActivity(),data,handler); rv.setAdapter(simpleRecycleAdapter); }else { Toast.makeText(getActivity(),"已取消为空",Toast.LENGTH_SHORT).show(); } } } @Override public void onFailed() { } }); } }
YiZhiFuFragment
package bwie.com.a20180113zhoulian.view.fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; 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 android.widget.Toast; import com.google.gson.Gson; import java.util.HashMap; import java.util.List; import java.util.Map; import bwie.com.a20180113zhoulian.R; import bwie.com.a20180113zhoulian.model.BaseObserver; import bwie.com.a20180113zhoulian.model.bean.YiZhiFuBean; import bwie.com.a20180113zhoulian.utils.RetrofitFactory; import bwie.com.a20180113zhoulian.view.adapter.YiZhiFuAdapter; /** * Created by dell on 2017/12/21. */ public class YiZhiFuFragment extends Fragment { private RecyclerView rv; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if(msg.what==1) { Toast.makeText(getActivity(),"查看订单~",Toast.LENGTH_SHORT).show(); huqushuju(); } } }; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.yizhifu_layout, container, false); rv= view.findViewById(R.id.rv); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); huqushuju(); } private void huqushuju() { Map<String, String> prams=new HashMap<>(); prams.put("uid",11824+""); prams.put("status",1+""); prams.put("source","android"); RetrofitFactory.post("https://www.zhaoapi.cn/product/getOrders",prams).subscribe(new BaseObserver() { @Override public void onSuccess(String result) { YiZhiFuBean dingDanBean = new Gson().fromJson(result, YiZhiFuBean.class); if (dingDanBean.getMsg().equals("请求成功")) { List<YiZhiFuBean.DataBean> data = dingDanBean.getData(); if(data.size()>0) { rv.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false)); //设置适配器 YiZhiFuAdapter simpleRecycleAdapter = new YiZhiFuAdapter(getActivity(),data,handler); rv.setAdapter(simpleRecycleAdapter); } }else { Toast.makeText(getActivity(),"已支付为空",Toast.LENGTH_SHORT).show(); } } @Override public void onFailed() { } }); } }
FraHorder
package bwie.com.a20180113zhoulian.view.horder; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.Button; import android.widget.TextView; import bwie.com.a20180113zhoulian.R; /** * Created by dell on 2017/12/21. */ public class FraHorder extends RecyclerView.ViewHolder { public TextView textView; public TextView text_time; public TextView status; public TextView price; public Button btn; public FraHorder(View itemView) { super(itemView); textView = itemView.findViewById(R.id.text_title); price = itemView.findViewById(R.id.text_price); status = itemView.findViewById(R.id.status); text_time=itemView.findViewById(R.id.text_time); btn= itemView.findViewById(R.id.btn); } }
ShuHorder
package bwie.com.a20180113zhoulian.view.horder; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; import bwie.com.a20180113zhoulian.R; /** * Created by dell on 2018/1/17. */ public class ShuHorder extends RecyclerView.ViewHolder{ public TextView title; public SimpleDraweeView img; public TextView price; public ShuHorder(View itemView) { super(itemView); title = itemView.findViewById(R.id.title); img = itemView.findViewById(R.id.img); price = itemView.findViewById(R.id.price); } }
show.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!--根据选中和未选中的状态,去设置背景颜色的图片--> <item android:state_checked="true" android:drawable="@color/colorAccent"/> <item android:state_checked="false" android:drawable="@color/colorPrimary"/> <item android:drawable="@color/colorPrimary"/> </selector>
daizhuce_layout.xml
<?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.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout>
yiquxiao_layout.xml
<?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.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout>
yizhifu_layout.xml
<?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.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout>
yi_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_marginLeft="10dp" android:orientation="vertical" android:layout_weight="6" android:layout_width="0dp" android:layout_height="wrap_content"> <TextView android:text="sdsdsd" android:id="@+id/text_title" android:gravity="center" android:textSize="25dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:textColor="#f00" android:text="fgdgdh" android:id="@+id/text_price" android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_marginTop="5dp" android:text="fgdgdh" android:id="@+id/text_time" android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_weight="2" android:layout_width="0dp" android:layout_height="wrap_content"> <TextView android:textSize="20dp" android:text="sdsd" android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/btn" android:text="点击取消" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
item_text_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_marginLeft="10dp" android:orientation="vertical" android:layout_weight="6" android:layout_width="0dp" android:layout_height="wrap_content"> <TextView android:text="sdsdsd" android:id="@+id/text_title" android:gravity="center" android:textSize="25dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:textColor="#f00" android:text="fgdgdh" android:id="@+id/text_price" android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_marginTop="5dp" android:text="fgdgdh" android:id="@+id/text_time" android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_weight="2" android:layout_width="0dp" android:layout_height="wrap_content"> <TextView android:textSize="20dp" android:text="sdsd" android:id="@+id/status" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/btn" android:text="点击取消" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
activity_ding_dan_status.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:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="bwie.com.changteng20171221.view.activity.DingDanStatusActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:textSize="20dp" android:gravity="center" android:text="订单列表" android:layout_width="match_parent" android:layout_height="40dp" /> <ImageView android:src="@drawable/lv_icon" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> <RadioGroup android:id="@+id/rg" android:gravity="center" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="50dp"> <RadioButton android:checked="true" android:background="@drawable/show" android:id="@+id/rb1" android:gravity="center" android:button="@null" android:text="待支付" android:layout_weight="2" android:layout_width="0dp" android:layout_height="50dp" /> <RadioButton android:background="@drawable/show" android:id="@+id/rb2" android:gravity="center" android:button="@null" android:text="已支付" android:layout_weight="2" android:layout_width="0dp" android:layout_height="50dp" /> <RadioButton android:background="@drawable/show" android:id="@+id/rb3" android:gravity="center" android:button="@null" android:text="已取消" android:layout_weight="2" android:layout_width="0dp" android:layout_height="50dp" /> </RadioGroup> <FrameLayout android:id="@+id/fl" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </LinearLayout>
popwindow.xml
<?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:cacheColorHint="#00000000" android:orientation="vertical" > <ListView android:id="@+id/lv_dialog" android:layout_width="match_parent" android:layout_height="match_parent" android:cacheColorHint="#00000000"> </ListView> </LinearLayout>