简单实现京东订单功能

提示      慎重复制


1  网络权限

2  导入依赖 

compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'

导gsonjar包

3代码


主页面布局

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" tools:context="com.example.zhangkai20180427.MainActivity"
    android:orientation="vertical"
    >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="订单"
        android:layout_weight="9"
        android:layout_gravity="center"
        android:gravity="center"
        />
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
    android:layout_weight="1"
    android:id="@+id/btn"
    />

LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="待支付"
            android:id="@+id/onefu"
            />
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="已支付"
            android:id="@+id/twofu"
            />
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="已取消"
            android:id="@+id/threefu"
            />
    LinearLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fram"
    >FrameLayout>

LinearLayout>


item布局/
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:orientation="vertical"
    >

   <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/titledai"
            />
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/dai"
           android:layout_alignParentRight="true"
           />
   RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:text="价格 : "
        android:id="@+id/ll"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pricedai"
        android:layout_toRightOf="@+id/ll"
        />
RelativeLayout>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="创建时间:"
            android:id="@+id/yy"
            />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/yy"
    android:id="@+id/timedai"
    />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
              android:text="取消订单"
            android:layout_alignParentRight="true"
            android:id="@+id/btndai"
            />
    RelativeLayout>
LinearLayout>
第一个fragment的布局///
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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycle1"
        >android.support.v7.widget.RecyclerView>

LinearLayout>
第二个fragment的布局///
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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycle2"
        >android.support.v7.widget.RecyclerView>
LinearLayout>
没错 就改了个id------
第三个fragment的布局///
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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycle3"
        >android.support.v7.widget.RecyclerView>
LinearLayout>

弹出选择订单类型的popupwindow
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:orientation="vertical"
    android:background="#2510eb"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="待支付"
        android:id="@+id/dai"
        android:textColor="#ffffff"
        android:padding="20dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="已支付"
        android:id="@+id/yifu"
        android:textColor="#ffffff"
        android:padding="20dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="已取消"
        android:id="@+id/yixiao"
        android:textColor="#ffffff"
        android:padding="20dp"
        />

LinearLayout>

第一个适配器///
package com.example.zhangkai20180427.adapter;

import android.content.Context;
import android.content.DialogInterface;
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 android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zhangkai20180427.R;
import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.presenter.LoginPresenterorderdd;
import com.example.zhangkai20180427.presenter.Presenterorderdd;
import com.example.zhangkai20180427.view.LoginVieworderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class MyAdapterorderdd1 extends  RecyclerView.Adapter<MyAdapterorderdd1.ViewHolder> implements LoginVieworderdd {
private Context context;
private List list;
private int Viewk_0=0;
private int Viewk_1=1;
private int Viewk_2=2;
private int Viewk_3=3;
private View view;
private LoginPresenterorderdd loginpresenter;


public MyAdapterorderdd1(Context context, List list){
        this.context = context;
        this.list=list;
        }




/** * * @param parent * @param viewType * @return */
@Override
public MyAdapterorderdd1.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        view = LayoutInflater.from(context).inflate(R.layout.itemoneorderdd,parent,false);
        RecyclerView.ViewHolder viewHolder = new ViewHolder(view);
        Log.d("aaa",viewType+"");
        return (ViewHolder) viewHolder;
        }


    /*   生命自己的一个事件回调接口*/
public interface OnItemClickListener{
    /*条目点击事件 */
    void setOnItemClick(View view,int position);
    /*条目长按事件 */
    void setOnItemLongClick(View view,int position);
}
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
    @Override
    public void onBindViewHolder(MyAdapterorderdd1.ViewHolder holder, final int position) {

       loginpresenter=new Presenterorderdd(this);

              Log.d("uuu",list.get(position).getStatus()+"");
        if((list.get(position).getStatus()==0)){


            Log.d("ikikik",list.get(0).getPrice()+"");
            if(null==list.get(position).getTitle()){
                holder.titledai.setText("");
            }else{
                holder.titledai.setText(list.get(position).getTitle().toString());
            }
            holder.dai.setText("待支付");
            holder.pricedai.setText(list.get(position).getPrice()+"");
            holder.timedai.setText(list.get(position).getCreatetime());
        }

        //删除订单
        holder.btndai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //    通过AlertDialog.Builder这个类来实例化我们的一个AlertDialog的对象
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                //    设置Title的图标
                builder.setIcon(R.mipmap.ic_launcher);
                //    设置Title的内容
                builder.setTitle("注意");
                //    设置Content来显示一个信息
                builder.setMessage("确定删除吗?");
                //    设置一个PositiveButton
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                     //删除当前订单
                    loginpresenter.updatechuan(list.get(position).getUid(),list.get(position).getOrderid(),list.get(position).getStatus());
                    notifyDataSetChanged();
                    }
                });
                //    设置一个NegativeButton
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Toast.makeText(context, "太好了", Toast.LENGTH_SHORT).show();
                    }
                });


                //    显示出该对话框
                builder.show();

            }
        });




        if(null != onItemClickListener) {
           /*回调点击事件*/
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    onItemClickListener.setOnItemClick(v,position);
                } });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onItemClickListener.setOnItemLongClick(v,position);
                    return true;
                } });
        }
    }
    @Override public int getItemCount() {
        return list.size();
    }


class ViewHolder extends RecyclerView.ViewHolder{
    TextView  titledai;
    TextView  dai;
    TextView  pricedai;
    TextView  timedai;
    Button btndai;

    public ViewHolder(View itemView) {
        super(itemView);
        titledai= itemView.findViewById(R.id.titledai);
        dai=itemView.findViewById(R.id.dai);
        pricedai=itemView.findViewById(R.id.pricedai);
        timedai=itemView.findViewById(R.id.timedai);
        btndai= itemView.findViewById(R.id.btndai);
    }
}





    @Override
    public void indentsuccess(SuccessBeanorderdd bean) {

    }

    @Override
    public void indentfailed(SuccessBeanorderdd bean) {

    }

    @Override
    public void updateorder(String d) {
     Log.d("bgbgbg",d);
    }

    @Override
    public void updateorderfailed(String d) {

    }
}

第二个适配器//
package com.example.zhangkai20180427;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class MyAdapterorderdd2 extends  RecyclerView.Adapter {

    private Context context;
    private List list;
    private int Viewk_0=0;
    private int Viewk_1=1;
    private int Viewk_2=2;
    private int Viewk_3=3;
    private View view;



    public MyAdapterorderdd2(Context context, List list){
        this.context = context;
        this.list=list;
    }


    /** * * @param parent * @param viewType * @return */
    @Override
    public MyAdapterorderdd2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        view = LayoutInflater.from(context).inflate(R.layout.itemoneorderdd,parent,false);
        RecyclerView.ViewHolder viewHolder = new ViewHolder(view);
        Log.d("aaa",viewType+"");
        return (ViewHolder) viewHolder;
    }
    /*   生命自己的一个事件回调接口*/
    public interface OnItemClickListener{
        /*条目点击事件 */
        void setOnItemClick(View view,int position);
        /*条目长按事件 */
        void setOnItemLongClick(View view,int position);
    }
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
    @Override
    public void onBindViewHolder(MyAdapterorderdd2.ViewHolder holder, final int position) {
        Log.d("pcpcpc",list.get(position).getStatus()+"");
        if((list.get(position).getStatus()==1)){
            Log.d("ioioio",list.get(0).getPrice()+"");
            if(null==list.get(position).getTitle()){
                holder.titledai.setText("");
            }else{
                holder.titledai.setText(list.get(position).getTitle().toString());
            }

            holder.dai.setText("已支付");
            holder.pricedai.setText(list.get(position).getPrice()+"");
            holder.timedai.setText(list.get(position).getCreatetime());
        }



        if(null != onItemClickListener) {
           /*回调点击事件*/
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    onItemClickListener.setOnItemClick(v,position);
                } });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onItemClickListener.setOnItemLongClick(v,position);
                    return true;
                } });
        }
    }
    @Override public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        TextView titledai;
        TextView  dai;
        TextView  pricedai;
        TextView  timedai;
        Button btndai;

        public ViewHolder(View itemView) {
            super(itemView);
            titledai= itemView.findViewById(R.id.titledai);
            dai=itemView.findViewById(R.id.dai);
            pricedai=itemView.findViewById(R.id.pricedai);
            timedai=itemView.findViewById(R.id.timedai);
            btndai= itemView.findViewById(R.id.btndai);
        }
    }
}


第三个适配器

 
package com.example.zhangkai20180427;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/5/2 0002.
 */

public class MyAdapterorderdd3 extends  RecyclerView.Adapter {


    private Context context;
    private List list;
    private int Viewk_0=0;
    private int Viewk_1=1;
    private int Viewk_2=2;
    private int Viewk_3=3;
    private View view;


    public MyAdapterorderdd3(Context context, List list){
        this.context = context;
        this.list=list;
    }


    /** * * @param parent * @param viewType * @return */
    @Override
    public MyAdapterorderdd3.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        view = LayoutInflater.from(context).inflate(R.layout.itemoneorderdd,parent,false);
        RecyclerView.ViewHolder viewHolder = new ViewHolder(view);
        Log.d("aaa",viewType+"");
        return (ViewHolder) viewHolder;
    }
    /*   生命自己的一个事件回调接口*/
    public interface OnItemClickListener{
        /*条目点击事件 */
        void setOnItemClick(View view,int position);
        /*条目长按事件 */
        void setOnItemLongClick(View view,int position);
    }
    private OnItemClickListener onItemClickListener;
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
    @Override
    public void onBindViewHolder(MyAdapterorderdd3.ViewHolder holder, final int position) {
        Log.d("pcpcpc",list.get(position).getStatus()+"");
        if((list.get(position).getStatus()==2)){
            Log.d("ioioio",list.get(0).getPrice()+"");
            if(null==list.get(position).getTitle()){
                holder.titledai.setText("");
            }else{
                holder.titledai.setText(list.get(position).getTitle().toString());
            }

            holder.dai.setText("已取消");
            holder.pricedai.setText(list.get(position).getPrice()+"");
            holder.timedai.setText(list.get(position).getCreatetime());
        }



        if(null != onItemClickListener) {
           /*回调点击事件*/
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    onItemClickListener.setOnItemClick(v,position);
                } });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onItemClickListener.setOnItemLongClick(v,position);
                    return true;
                } });
        }
    }
    @Override public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        TextView titledai;
        TextView  dai;
        TextView  pricedai;
        TextView  timedai;
        Button btndai;

        public ViewHolder(View itemView) {
            super(itemView);
            titledai= itemView.findViewById(R.id.titledai);
            dai=itemView.findViewById(R.id.dai);
            pricedai=itemView.findViewById(R.id.pricedai);
            timedai=itemView.findViewById(R.id.timedai);
            btndai= itemView.findViewById(R.id.btndai);
        }
    }

}
MainActivity
package com.example.zhangkai20180427;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.zhangkai20180427.fragment.Oneorderdd;
import com.example.zhangkai20180427.fragment.Threeorderdd;
import com.example.zhangkai20180427.fragment.Twoorderdd;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button onefu;
    private Button twofu;
    private Button threefu;
    private FrameLayout fram;
    private Button button;
    private ImageView btn;
    private PopupMenu popupMenu;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    private void initView() {
        onefu = (Button) findViewById(R.id.onefu);
        twofu = (Button) findViewById(R.id.twofu);
        threefu = (Button) findViewById(R.id.threefu);
        fram = (FrameLayout) findViewById(R.id.fram);
        btn = (ImageView) findViewById(R.id.btn);


        onefu.setOnClickListener(this);
        twofu.setOnClickListener(this);
        threefu.setOnClickListener(this);

        //点击弹出pupwindow
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 用于PopupWindowView
                    View contentView=LayoutInflater.from(MainActivity.this).inflate(R.layout.popuporderdd, null, false);
                   // 创建PopupWindow对象,其中:
                     // 第一个参数是用于PopupWindow中的View,第二个参数是PopupWindow的宽度,
                     // 第三个参数是PopupWindow的高度,第四个参数指定PopupWindow能否获得焦点
                     PopupWindow window=new PopupWindow(contentView,150,300, true);
                    // 设置PopupWindow的背景
                   window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    // 设置PopupWindow是否能响应外部点击事件
                     window.setOutsideTouchable(true);
                     // 设置PopupWindow是否能响应点击事件
                    window.setTouchable(true);
                    // 显示PopupWindow,其中:
                     // 第一个参数是PopupWindow的锚点,第二和第三个参数分别是PopupWindow相对锚点的xy偏移
                    window.showAsDropDown(btn,30,0);


                    // 或者也可以调用此方法显示PopupWindow,其中:
                     // 第一个参数是PopupWindow的父View,第二个参数是PopupWindow相对父View的位置,
                    // 第三和第四个参数分别是PopupWindow相对父Viewxy偏移
                  // window.showAtLocation(parent, gravity, x, y);
                  //设置出入动画  自定义的
                window.setAnimationStyle(R.style.popup);

                TextView dai=contentView.findViewById(R.id.dai);
                TextView yifu=contentView.findViewById(R.id.yifu);
                TextView yixiao=contentView.findViewById(R.id.yixiao);

                dai.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        //onefu是其他的按钮  不在自定义popup布局中
                        onefu.performClick();
                    }
                });
                yifu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       twofu.performClick();
                    }
                });
                yixiao.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        threefu.performClick();
                    }
                });



            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.onefu:
//动态添加fragment
                //1.获得fragment的管理类
                FragmentManager manager = getSupportFragmentManager();
                //2.开启事务
                FragmentTransaction transaction = manager.beginTransaction();
                //3.添加fragment,第一个参数:代表容器的id    第二个参数:fragment的对象
                transaction.replace(R.id.fram, new Oneorderdd());
                //4.提交
                transaction.commit();
                break;
            case R.id.twofu:
                //1.获得fragment的管理类
                FragmentManager manager2 = getSupportFragmentManager();
                //2.开启事务
                FragmentTransaction transaction2 = manager2.beginTransaction();
                //3.添加fragment,第一个参数:代表容器的id    第二个参数:fragment的对象
                transaction2.replace(R.id.fram, new Twoorderdd());
                //4.提交
                transaction2.commit();
                break;
            case R.id.threefu:
                //1.获得fragment的管理类
                FragmentManager manager3 = getSupportFragmentManager();
                //2.开启事务
                FragmentTransaction transaction3 = manager3.beginTransaction();
                //3.添加fragment,第一个参数:代表容器的id    第二个参数:fragment的对象
                transaction3.replace(R.id.fram, new Threeorderdd());
                //4.提交
                transaction3.commit();
                break;
        }
    }
}
 


实体类 自己建
SuccessBeanorderdd


第一个fragment //

package com.example.zhangkai20180427.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhangkai20180427.R;
import com.example.zhangkai20180427.adapter.MyAdapterorderdd1;
import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.presenter.LoginPresenterorderdd;
import com.example.zhangkai20180427.presenter.Presenterorderdd;
import com.example.zhangkai20180427.view.LoginVieworderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class Oneorderdd extends Fragment implements LoginVieworderdd {

    private RecyclerView recycle1;
    private LoginPresenterorderdd loginPresenter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v= inflater.inflate(R.layout.onexmlorderdd, null);

        recycle1 = v.findViewById(R.id.recycle1);

        loginPresenter = new Presenterorderdd(this);

        loginPresenter.indentuid("75");

        return v;
    }


    @Override
    public void indentsuccess(SuccessBeanorderdd bean) {
        Log.d("vvv",bean.getMsg().toString());
        List list=bean.getData();


        Log.d("zzz",list.get(0).getPrice()+"");
        recycle1.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));

//设置分割线
        recycle1.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));

//设置适配器
        MyAdapterorderdd1 adapter = new MyAdapterorderdd1(getContext(),list);
        recycle1.setAdapter(adapter);

        Log.d("tyty","555");


    }

    @Override
    public void indentfailed(SuccessBeanorderdd bean) {

    }

    @Override
    public void updateorder(String d) {

    }

    @Override
    public void updateorderfailed(String d) {

    }
}

第二个fragment// 

package com.example.zhangkai20180427.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhangkai20180427.MyAdapterorderdd2;
import com.example.zhangkai20180427.R;
import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.presenter.LoginPresenterorderdd;
import com.example.zhangkai20180427.presenter.Presenterorderdd;
import com.example.zhangkai20180427.view.LoginVieworderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class Twoorderdd extends Fragment implements LoginVieworderdd {



    private RecyclerView recycle2;
    private LoginPresenterorderdd loginPresenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v= inflater.inflate(R.layout.twoxmlorderdd, null);
        recycle2 = v.findViewById(R.id.recycle2);
        loginPresenter = new Presenterorderdd(this);
        loginPresenter.indentuid("75");
        return v;
    }



    @Override
    public void indentsuccess(SuccessBeanorderdd bean) {
        Log.d("vvv",bean.getMsg().toString());
        List list=bean.getData();


        Log.d("zzz",list.get(0).getPrice()+"");
        recycle2.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));
//设置分割线
        recycle2.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
//设置适配器
        MyAdapterorderdd2 adapter = new MyAdapterorderdd2(getContext(),list);
        recycle2.setAdapter(adapter);

        Log.d("tyty","555");

    }

    @Override
    public void indentfailed(SuccessBeanorderdd bean) {

    }

    @Override
    public void updateorder(String d) {

    }

    @Override
    public void updateorderfailed(String d) {

    }
}

第三个fragmentment//
 
package com.example.zhangkai20180427.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhangkai20180427.MyAdapterorderdd3;
import com.example.zhangkai20180427.R;
import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.presenter.LoginPresenterorderdd;
import com.example.zhangkai20180427.presenter.Presenterorderdd;
import com.example.zhangkai20180427.view.LoginVieworderdd;

import java.util.List;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class Threeorderdd extends Fragment implements LoginVieworderdd {


    private RecyclerView recycle3;
    private LoginPresenterorderdd loginPresenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v= inflater.inflate(R.layout.threexmlorderdd, null);

        recycle3 = v.findViewById(R.id.recycle3);


        loginPresenter = new Presenterorderdd(this);

        loginPresenter.indentuid("75");


        return v;
    }


    @Override
    public void indentsuccess(SuccessBeanorderdd bean) {
        List list=bean.getData();


        Log.d("zzz",list.get(0).getPrice()+"");
        recycle3.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false));

//设置分割线
        recycle3.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));

//设置适配器
        MyAdapterorderdd3 adapter = new MyAdapterorderdd3(getContext(),list);
        recycle3.setAdapter(adapter);
    }

    @Override
    public void indentfailed(SuccessBeanorderdd bean) {

    }

    @Override
    public void updateorder(String d) {

    }

    @Override
    public void updateorderfailed(String d) {

    }

}
model层接口//
package com.example.zhangkai20180427.model;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public interface LoginModelorderdd {

    interface  Inside{
        void indentsuccess(SuccessBeanorderdd bean);
        void indentfailed(SuccessBeanorderdd bean);

        void updateorder(String d);
        void updateorderfailed(String d);
    }

    void vityy(String uid,Inside inside);

    void vityyupdate(int uid,int orderld,int status,Inside inside);

}
model层类

package com.example.zhangkai20180427.model;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.ok.OkHttpUtilsorderdd;
import com.example.zhangkai20180427.ok.OnFinishListenerorderdd;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class Modelorderdd implements LoginModelorderdd {
    @Override
    public void vityy(String uid, final Inside inside) {

        OkHttpUtilsorderdd ok= OkHttpUtilsorderdd.getInstance();

        Map map=new HashMap<>();
        map.put("uid",uid);

        //请求轮播图
        ok.doGet("https://www.zhaoapi.cn/product/getOrders", map,new OnFinishListenerorderdd() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();

                SuccessBeanorderdd b=gson.fromJson(result,SuccessBeanorderdd.class);
                inside.indentsuccess(b);
            }
            @Override
            public void onFailed(String msg) {
            }
        });
    }

    @Override
    public void vityyupdate(int uid, int orderld, int status, final Inside inside) {

        OkHttpUtilsorderdd ok= OkHttpUtilsorderdd.getInstance();

        Map map=new HashMap<>();
        map.put("uid",uid+"");
        map.put("orderld",orderld+"");
        map.put("status",status+"");



        ok.doGet("https://www.zhaoapi.cn/product/updateOrder", map,new OnFinishListenerorderdd() {
            @Override
            public void onSuccess(String result) {
                Gson gson=new Gson();

                SuccessBeanorderdd b=gson.fromJson(result,SuccessBeanorderdd.class);
                inside.updateorder(b.getMsg().toString());
            }
            @Override
            public void onFailed(String msg) {
            }
        });


    }
}
p层接口//

 
package com.example.zhangkai20180427.presenter;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public interface LoginPresenterorderdd {

    void indentuid(String uid);

    void updatechuan(int uid,int orderld,int status);

}
p层类/
package com.example.zhangkai20180427.presenter;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;
import com.example.zhangkai20180427.model.LoginModelorderdd;
import com.example.zhangkai20180427.model.Modelorderdd;
import com.example.zhangkai20180427.view.LoginVieworderdd;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class Presenterorderdd implements LoginPresenterorderdd,LoginModelorderdd.Inside  {
    private LoginVieworderdd loginView;
    private LoginModelorderdd loginModel;

    public Presenterorderdd(LoginVieworderdd loginView){
        this.loginView=loginView;
        this.loginModel=new Modelorderdd();
    }

    @Override
    public void indentuid(String uid) {
       loginModel.vityy(uid,this);
    }

    @Override
    public void updatechuan(int uid, int orderld, int status) {
         loginModel.vityyupdate(uid,orderld,status,this);
    }

    @Override
    public void indentsuccess(SuccessBeanorderdd bean) {
        loginView.indentsuccess(bean);
    }

    @Override
    public void indentfailed(SuccessBeanorderdd bean) {
       loginView.indentfailed(bean);
    }

    @Override
    public void updateorder(String d) {
    loginView.updateorder(d);
    }

    @Override
    public void updateorderfailed(String d) {
    loginView.updateorderfailed(d);
    }
}

view层接口/ 
package com.example.zhangkai20180427.view;

import com.example.zhangkai20180427.bean.SuccessBeanorderdd;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public interface LoginVieworderdd {

    void indentsuccess(SuccessBeanorderdd bean);
    void indentfailed(SuccessBeanorderdd bean);


    void updateorder(String d);
    void updateorderfailed(String d);
}

网络请求工具类第一个 
package com.example.zhangkai20180427.ok;

import android.os.Handler;
import android.util.Log;

import java.io.IOException;
import java.util.Map;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
 * Created by Administrator on 2018/4/27 0027.
 */

public class OkHttpUtilsorderdd {
    private static OkHttpUtilsorderdd okHttpUtils = null;
    private static Handler handler = new Handler();

    private OkHttpUtilsorderdd(){}
    /**
     * 获取当前这个类的实例
     * @return
     */
    public static OkHttpUtilsorderdd getInstance(){
        if(null == okHttpUtils){
            synchronized (OkHttpUtilsorderdd.class){
                if(null == okHttpUtils){
                    okHttpUtils = new OkHttpUtilsorderdd();
                }
            }
        }
        return okHttpUtils;
    }
    /**
     * get请求
     * @param path
     * @param map
     */
    public void doGet(String path, Map map, final OnFinishListenerorderdd onFinishListener){



        StringBuilder sb = null;

        for (String key : map.keySet()) {
            //login?name=124e3434&p=ere

            if(null == sb){
                sb = new StringBuilder();
                sb.append("?");
            }else{

                sb.append("&");

            }

            //拼接参数
            sb.append(key).append("=").append(map.get(key));
        }


        OkHttpClient okHttpClient = new OkHttpClient();



/* //应用拦截器
OkHttpClient okHttpClient1=new OkHttpClient.Builder()
.addInterceptor(new CommonParamsinterceptor())
.build();*/

        final Request request = new Request.Builder()
                .url(path+sb.toString())
                .get()
                .build();
        Log.d("gggg",path+sb.toString());

        okhttp3.Call call = okHttpClient/*使用拦截器此处需要换上拦截器名*/.newCall(request);
        call.enqueue(new Callback() {

            public void onFailure(okhttp3.Call call, final IOException e) {

                //在子线程
                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        onFinishListener.onFailed(e.getMessage());

                    }
                });
            }

            public void onResponse(okhttp3.Call call, final Response response) throws IOException {


                final String result = response.body().string();


                handler.post(new Runnable() {
                    @Override
                    public void run() {

                        try {

                            onFinishListener.onSuccess(result);

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });

            }
        });

    }
}

网络请求工具类第二个/
package com.example.zhangkai20180427.ok;

/**
 * Created by Administrator on 2018/4/27 0027.
 */

public interface OnFinishListenerorderdd {
    void onSuccess(String result);
    void onFailed(String msg);

}



你可能感兴趣的:(简单实现京东订单功能)