//activity_main
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.bwie.test.zhoumoni_03.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="20sp"
android:text="订单列表"/>
<ImageView
android:id="@+id/image_btn"
android:layout_width="25dp"
android:layout_height="25dp"
android:clickable="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:background="@drawable/lv_icon"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/text_daizhi"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="match_parent"
android:textSize="16sp"
android:background="@drawable/biankuang"
android:text="待支付"/>
<TextView
android:id="@+id/text_yizhi"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="match_parent"
android:textSize="16sp"
android:background="@drawable/biankuang"
android:text="已支付"/>
<TextView
android:id="@+id/text_yiqu"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="match_parent"
android:textSize="16sp"
android:background="@drawable/biankuang"
android:text="已取消"/>
</LinearLayout>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
//frag_daizhi
<?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">
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/smart_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_daizhi"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</ScrollView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<RelativeLayout
android:id="@+id/relative_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
//frag_yiqu
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
//frag_yizhi
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:background="#b6b6b6"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
//item_dingdan
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/text_title"
android:layout_weight="1"
android:layout_width="0dp"
android:gravity="bottom"
android:layout_height="match_parent"
android:text="11111"/>
<TextView
android:id="@+id/text_daizhifu"
android:layout_width="50dp"
android:gravity="bottom"
android:layout_height="match_parent"
android:textColor="#f00"
android:text="待支付"/>
</LinearLayout>
<TextView
android:id="@+id/text_price"
android:gravity="bottom"
android:textColor="#ff0000"
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="1111"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/text_tame"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:layout_height="match_parent"
android:text="1111"/>
<TextView
android:id="@+id/text_btn"
android:layout_width="70dp"
android:gravity="center"
android:layout_gravity="bottom"
android:layout_height="30dp"
android:background="@drawable/biankuang"
android:text="取消订单"/>
</LinearLayout>
<TextView
android:layout_marginTop="15dp"
android:clickable="true"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#9999"/>
</LinearLayout>
//item_popup
<?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">
<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/btn_daizhi"
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_height="0dp"
android:textSize="16sp"
android:padding="15dp"
android:background="@drawable/select_dianji"
android:text="待支付"/>
<TextView
android:id="@+id/btn_yizhi"
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_height="0dp"
android:textSize="16sp"
android:padding="15dp"
android:background="@drawable/select_dianji"
android:text="已支付"/>
<TextView
android:id="@+id/btn_yiqu"
android:layout_width="match_parent"
android:layout_weight="1"
android:gravity="center"
android:layout_height="0dp"
android:textSize="16sp"
android:padding="15dp"
android:background="@drawable/select_dianji"
android:text="已取消"/>
</LinearLayout>
</RelativeLayout>
drawable文件夹下//biankuang
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="0.2dp" android:color="#000"/>
<solid android:color="#fff"/>
</shape>
//select_dianji
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/beijing"/>
<item android:state_pressed="false" android:drawable="@color/baise"/>
<item android:drawable="@color/baise"/>
</selector>
values文件夹下//colors
<?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="beijing">#69C3D7</color>
<color name="baise">#ffffff</color>
<color name="hongde">#ff0000</color>
</resources>
//MainActivity
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private ImageView image_btn; private TextView text_daizhi; private TextView text_yizhi; private TextView text_yiqu; private FrameLayout frame_layout; private View item_popup; private View view; private PopupWindow popupWindow; private TextView btn_daizhi; private TextView btn_yizhi; private TextView btn_yiqu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //隐藏原有标题 getSupportActionBar().hide(); //查找控件 image_btn = (ImageView) findViewById(R.id.image_btn); text_daizhi = (TextView) findViewById(R.id.text_daizhi); text_yizhi = (TextView) findViewById(R.id.text_yizhi); text_yiqu = (TextView) findViewById(R.id.text_yiqu); frame_layout = (FrameLayout) findViewById(R.id.frame_layout); //https://www.zhaoapi.cn/product/updateOrder?uid=4427&status=1 //https://www.zhaoapi.cn/product/updateOrder?uid=4427&orderId= //https://www.zhaoapi.cn/product/getOrders?uid=4427&status2 text_daizhi.setOnClickListener(this); text_yizhi.setOnClickListener(this); text_yiqu.setOnClickListener(this); Frag_Daizhi frag_daizhi = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi).commit(); item_popup = View.inflate(this, R.layout.item_popup, null); view = View.inflate(this, R.layout.activity_main, null); popupWindow = new PopupWindow(item_popup , ActionBar.LayoutParams.WRAP_CONTENT,ActionBar.LayoutParams.WRAP_CONTENT); popupWindow.setTouchable(true); btn_daizhi = item_popup.findViewById(R.id.btn_daizhi); btn_yizhi = item_popup.findViewById(R.id.btn_yizhi); btn_yiqu = item_popup.findViewById(R.id.btn_yiqu); btn_daizhi.setOnClickListener(this); btn_yizhi.setOnClickListener(this); btn_yiqu.setOnClickListener(this); image_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popupWindow.showAsDropDown(image_btn); } }); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.text_daizhi: Frag_Daizhi frag_daizhi = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi).commit(); break; case R.id.text_yizhi: Frag_YiZhi frag_yiZhi = new Frag_YiZhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiZhi).commit(); break; case R.id.text_yiqu: Frag_YiQu frag_yiQu = new Frag_YiQu(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiQu).commit(); break; case R.id.btn_daizhi: Frag_Daizhi frag_daizhi2 = new Frag_Daizhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_daizhi2).commit(); popupWindow.dismiss(); break; case R.id.btn_yizhi: Frag_YiZhi frag_yiZhi2 = new Frag_YiZhi(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiZhi2).commit(); popupWindow.dismiss(); break; case R.id.btn_yiqu: Frag_YiQu frag_yiQu2 = new Frag_YiQu(); getSupportFragmentManager().beginTransaction() .replace(R.id.frame_layout,frag_yiQu2).commit(); popupWindow.dismiss(); break; } } }
adapter//MyDingDanAdapter
public class MyDingDanAdapter extends RecyclerView.Adapter<MyDingDanHolder>{ private final Context context; private final List<MyDataDingDanBean.DataBean> list; private Presenterdingdanq presenter; private int page; public MyDingDanAdapter(Context context, List<MyDataDingDanBean.DataBean> list, Presenterdingdanq presenter, int page) { this.context = context; this.list = list; this.presenter = presenter; this.page = page; } @Override public MyDingDanHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.item_dingdan, parent, false); MyDingDanHolder holder = new MyDingDanHolder(view); return holder; } @Override public void onBindViewHolder(MyDingDanHolder holder, final int position) { holder.text_title.setText(list.get(position).getTitle()); holder.text_price.setText("价格:"+list.get(position).getPrice()); holder.text_tame.setText(list.get(position).getCreatetime()); if (list.get(position).getStatus() == 0){ holder.text_daizhifu.setText("待支付"); holder.text_daizhifu.setTextColor(Color.RED); holder.text_btn.setText("取消订单"); holder.text_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("提示"); builder.setMessage("确定要取消订单吗?"); builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Map<String, String> params=new HashMap<>(); params.put("uid","3690"); params.put("orderId", String.valueOf(list.get(position).getOrderid())); params.put("status", String.valueOf(2)); OkHttp3Util.doPost(ApiUtil.genxin, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ Log.d("+++++++++响哥1", String.valueOf(list.get(position).getStatus())); presenter.getDingUrl(ApiUtil.dingdan,page); } } }); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); builder.show(); } }); } else if (list.get(position).getStatus() == 1){ holder.text_daizhifu.setText("已支付"); holder.text_daizhifu.setTextColor(Color.BLACK); holder.text_btn.setText("查看订单"); } else if (list.get(position).getStatus() == 2){ holder.text_daizhifu.setText("已取消"); holder.text_daizhifu.setTextColor(Color.BLACK); holder.text_btn.setText("查看订单"); holder.text_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("提示"); builder.setMessage("确定循环利用吗?"); builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Map<String, String> params = new HashMap<>(); params.put("uid", "3690"); params.put("orderId", String.valueOf(list.get(position).getOrderid())); params.put("status", String.valueOf(0)); OkHttp3Util.doPost(ApiUtil.genxin, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()) { Log.d("+++++++++响哥", String.valueOf(list.get(position).getStatus())); presenter.getDingUrl(ApiUtil.dingdan, page); } } }); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); builder.show(); } }); } } @Override public int getItemCount() { return list.size(); } }
holder文件夹下//MyDingDanHolder
public class MyDingDanHolder extends RecyclerView.ViewHolder{ public TextView text_title; public TextView text_daizhifu; public TextView text_price; public TextView text_tame; public TextView text_btn; public MyDingDanHolder(View itemView) { super(itemView); text_title = itemView.findViewById(R.id.text_title); text_daizhifu = itemView.findViewById(R.id.text_daizhifu); text_price = itemView.findViewById(R.id.text_price); text_tame = itemView.findViewById(R.id.text_tame); text_btn = itemView.findViewById(R.id.text_btn); } }
M层//DingdanModel
public class DingdanModel{ private Presenterdingdanq presenter; public DingdanModel(Presenterdingdanq presenter){ this.presenter = presenter; } public void getDingUrl(String dingdan, int page){ Map<String, String> params = new HashMap<>(); params.put("uid","3690"); params.put("page",page+""); OkHttp3Util.doPost(dingdan, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ String json = response.body().string(); MyDataDingDanBean myDingDanBean = new Gson().fromJson(json, MyDataDingDanBean.class); presenter.getDingDanBean(myDingDanBean); } } }); } }
P层//Presenterdingdanq
public class Presenterdingdanq implements PresenterPortdingdan{ private Maindingdan main; private final DingdanModel model; public Presenterdingdanq(Maindingdan main){ model = new DingdanModel(this); this.main = main; } @Override public void getDingDanBean(MyDataDingDanBean myDingDanBean) { main.getDingDanBean(myDingDanBean); } public void getDingUrl(String diangdan, int page){ model.getDingUrl(diangdan,page); } }
//PresenterPortdingdan
public interface PresenterPortdingdan { void getDingDanBean(MyDataDingDanBean myDingDanBean); }
V层//Maindingdan
public interface Maindingdan { void getDingDanBean(MyDataDingDanBean myDingDanBean); }
fragment文件夹下//Frag_Daizhi
public class Frag_Daizhi extends Fragment implements Maindingdan{ private List<MyDataDingDanBean.DataBean> list = new ArrayList<>(); private View view; private RecyclerView recycler_daizhi; private Presenterdingdanq presenter; private RelativeLayout relative_bar; private SmartRefreshLayout smart_refresh; private int page = 0; private MyDingDanAdapter adapter; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_daizhi, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); recycler_daizhi = view.findViewById(R.id.recycler_daizhi); relative_bar = view.findViewById(R.id.relative_bar); smart_refresh = view.findViewById(R.id.smart_refresh); presenter = new Presenterdingdanq(this); } @Override public void onResume() { super.onResume(); relative_bar.setVisibility(View.VISIBLE); presenter.getDingUrl(ApiUtil.dingdan, page); } @Override public void getDingDanBean(final MyDataDingDanBean myDingDanBean) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (myDingDanBean!=null){ list.addAll(myDingDanBean.getData()); myAdapter(); relative_bar.setVisibility(View.GONE); smart_refresh.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { list.clear(); list.addAll(0, myDingDanBean.getData()); myAdapter(); smart_refresh.finishRefresh(); } }); smart_refresh.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(RefreshLayout refreshlayout) { list.clear(); page++; presenter.getDingUrl(ApiUtil.dingdan,page); onResume(); list.addAll(myDingDanBean.getData()); myAdapter(); smart_refresh.finishLoadmore(); } }); } } }); } public void myAdapter(){ if (adapter==null){ recycler_daizhi.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL, false)); adapter = new MyDingDanAdapter(getActivity(), list,presenter,page); recycler_daizhi.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); } } }
//Frag_YiQu
public class Frag_YiQu extends Fragment{ private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_yiqu, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } }
//Frag_YiZhi
public class Frag_YiZhi extends Fragment { private View view; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.frag_yizhi, container, false); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } }
util文件夹下//ApiUtil
public class ApiUtil { //uid 用户id字段 String类型 必传 //status 订单状态 String类型 非必传(筛选订单列表时,必传) public static String dingdan="https://www.zhaoapi.cn/product/getOrders"; //uid 用户id字段 String类型 必传 //orderId 订单id参数 String类型 必传 //status 订单状态 String类型 必传 public static String genxin="https://www.zhaoapi.cn/product/updateOrder"; }
//MyDataDingDanBean
public class MyDataDingDanBean { private String msg; private String code; private String page; private List<DataBean> data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getPage() { return page; } public void setPage(String page) { this.page = page; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { private String createtime; private int orderid; private double price; private int status; private String title; private int uid; public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public int getOrderid() { return orderid; } public void setOrderid(int orderid) { this.orderid = orderid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } } }
//jar包
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okio:okio:1.11.0' compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'//没有使用特殊Header,可以不加这行 compile files('libs/glide-3.7.0.jar') compile files('libs/gson-2.8.0.jar')<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"/>