retrofit+rxjava京东订单

1.先创建订单页面,并且设置fragment切换页面以及popuwindown

public class DingDanActivity extends AppCompatActivity implements View.OnClickListener {

    @BindView(R.id.detail_image_back)
    ImageView detailImageBack;
    @BindView(R.id.san_dian_pop)
    ImageView sanDianPop;
    @BindView(R.id.radio_group)
    RadioGroup radioGroup;
    TextView popDaiPay;
    TextView popAlreadyPay;
    TextView popCancel;
    private PopupWindow popupWindow;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ding_dan);
        ButterKnife.bind(this);

        detailImageBack.setOnClickListener(this);
        sanDianPop.setOnClickListener(this);

        findView();

        //popupwindown弹出框
        initPopUpWindown();

        int flag = getIntent().getIntExtra("flag", -1);

        //默认显示的是全部页面
        if (flag == -1) {

            getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAllOrder()).commit();
        } else {
            //如果从fragemnt跳转过来 需要展示自己的页面
            if (flag == 1) {//待支付
                radioGroup.check(R.id.radio_02);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit();
            } else if (flag == 2) {//已支付
                radioGroup.check(R.id.radio_03);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit();
            } else if (flag == 3) {//已取消
                radioGroup.check(R.id.radio_04);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit();
            }
        }


        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                switch (id) {
                    case R.id.radio_01://全部
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAllOrder()).commit();
                        break;
                    case R.id.radio_02://待支付
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit();
                        break;
                    case R.id.radio_03://已支付
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit();
                        break;
                    case R.id.radio_04://已取消
                        getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit();
                        break;
                }
            }
        });

    }

    private void findView() {
        popDaiPay = findViewById(R.id.pop_dai_pay);
        popAlreadyPay = findViewById(R.id.pop_already_pay);
        popCancel = findViewById(R.id.pop_cancel);
    }

    private void initPopUpWindown() {
        View view = View.inflate(DingDanActivity.this, R.layout.order_pop_layout, null);
        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());

        //找到控件
        popDaiPay = view.findViewById(R.id.pop_dai_pay);
        popAlreadyPay = view.findViewById(R.id.pop_already_pay);
        popCancel = view.findViewById(R.id.pop_cancel);

        popDaiPay.setOnClickListener(this);
        popAlreadyPay.setOnClickListener(this);
        popCancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.detail_image_back:
                finish();
                break;
            case R.id.san_dian_pop://弹出pop
                //判断一下当前radioGroup选中了哪一个RadioButton...设置展示的背景颜色
                int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
                switch (checkedRadioButtonId) {
                    case R.id.radio_02://待支付
                        popDaiPay.setBackgroundColor(Color.BLUE);
                        popAlreadyPay.setBackgroundColor(Color.YELLOW);
                        popCancel.setBackgroundColor(Color.YELLOW);
                        break;
                    case R.id.radio_03://已支付
                        popDaiPay.setBackgroundColor(Color.YELLOW);
                        popAlreadyPay.setBackgroundColor(Color.BLUE);
                        popCancel.setBackgroundColor(Color.YELLOW);
                        break;
                    case R.id.radio_04://已取消
                        popDaiPay.setBackgroundColor(Color.YELLOW);
                        popAlreadyPay.setBackgroundColor(Color.WHITE);
                        popCancel.setBackgroundColor(Color.YELLOW);
                        break;
                }

                popupWindow.showAsDropDown(sanDianPop);

                break;
            case R.id.pop_dai_pay://待支付
                radioGroup.check(R.id.radio_02);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentDaiPayOrder()).commit();
                popupWindow.dismiss();
                break;
            case R.id.pop_already_pay://已支付
                radioGroup.check(R.id.radio_03);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentAlreadyPayOrder()).commit();
                popupWindow.dismiss();
                break;
            case R.id.pop_cancel://已取消
                radioGroup.check(R.id.radio_04);
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_content, new FragmentCacelOrder()).commit();
                popupWindow.dismiss();
                break;
        }
    }
}

对应布局:

订单布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">


    <RelativeLayout
        android:id="@+id/detai_relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/detail_image_back"
            android:padding="5dp"
            android:layout_width="40dp"
            android:layout_height="40dp" />

        <TextView
            android:layout_centerInParent="true"
            android:text="我的订单"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageView
            android:id="@+id/san_dian_pop"
            android:padding="5dp"
            android:layout_alignParentRight="true"
            android:layout_width="40dp"
            android:layout_height="40dp" />

    </RelativeLayout>

    <RadioGroup
        android:id="@+id/radio_group"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="40dp">

        <RadioButton
            android:id="@+id/radio_01"
            android:checked="true"
            android:button="@null"
            android:gravity="center"
            android:text="全部"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />

        <RadioButton
            android:id="@+id/radio_02"
            android:button="@null"
            android:gravity="center"
            android:text="待支付"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />

        <RadioButton
            android:id="@+id/radio_03"
            android:button="@null"
            android:gravity="center"
            android:text="已支付"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />

        <RadioButton
            android:id="@+id/radio_04"
            android:button="@null"
            android:gravity="center"
            android:text="已取消"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="match_parent" />

    </RadioGroup>

    <FrameLayout
        android:id="@+id/frame_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</LinearLayout>

popupwindown布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <TextView
        android:gravity="center"
        android:id="@+id/pop_dai_pay"
        android:text="待支付"
        android:layout_width="80dp"
        android:layout_height="50dp" />

    <TextView
        android:gravity="center"
        android:id="@+id/pop_already_pay"
        android:text="已支付"
        android:layout_width="80dp"
        android:layout_height="50dp" />

    <TextView
        android:gravity="center"
        android:id="@+id/pop_cancel"
        android:text="已取消"
        android:layout_width="80dp"
        android:layout_height="50dp" />

</LinearLayout>

切换的第一个页面(所有订单)

public class FragmentAllOrder extends Fragment implements FragmentOrderListInter {

    private RecyclerView recyclerView;
    private SmartRefreshLayout smartRefreshLayout;
    private OrderListPresenter orderListPresenter;
    //分页
    private int page = 1;
    //大集合
    private List<OrderListBean.DataBean> listAll = new ArrayList<>();
    private OrderListAdapter orderListAdapter;
    private RelativeLayout relative_empty_order;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
        recyclerView = view.findViewById(R.id.recycler_order);
        smartRefreshLayout = view.findViewById(R.id.smart_refresh);
        relative_empty_order = view.findViewById(R.id.relative_empty_order);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        //获取订单列表的数据
        orderListPresenter = new OrderListPresenter(this);
        orderListPresenter.getOrderData(Api.ORDER_LIST_URL);

        smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                smartRefreshLayout.finishRefresh(2000);
            }
        });
        smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                page ++;
                orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
            }
        });
    }

    /**
     * 设置适配器
     */
    private void setAdapter() {

        if (orderListAdapter == null) {
            orderListAdapter = new OrderListAdapter(getActivity(), listAll);
            recyclerView.setAdapter(orderListAdapter);
        }else {
            orderListAdapter.notifyDataSetChanged();
        }

        smartRefreshLayout.finishLoadmore();

    }

    @Override
    public void onOrderDataSuccess(OrderListBean orderListBean) {
        try {
               if ("0".equals(orderListBean.getCode())) {
                //添加到大集合
                listAll.addAll(orderListBean.getData());

                if (listAll.size() == 0) {
                    relative_empty_order.setVisibility(View.VISIBLE);
                    smartRefreshLayout.setVisibility(View.GONE);
                }else {
                    relative_empty_order.setVisibility(View.GONE);
                    smartRefreshLayout.setVisibility(View.VISIBLE);
                }

                //设置适配器
                setAdapter();

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

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_order"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

    <RelativeLayout
        android:visibility="gone"
        android:id="@+id/relative_empty_order"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>

订单的适配器:

public class OrderListAdapter extends RecyclerView.Adapter<OrderListHolder> {
    private List<OrderListBean.DataBean> listAll;
    private Context context;
    AddCartBean updateOrderBean;

    public OrderListAdapter(Context context, List<OrderListBean.DataBean> listAll) {
        this.context = context;
        this.listAll = listAll;
    }

    @Override
    public OrderListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.order_item_layout, null);
        OrderListHolder orderListHolder = new OrderListHolder(view);
        return orderListHolder;
    }

    @Override
    public void onBindViewHolder(final OrderListHolder holder, int position) {
        final OrderListBean.DataBean dataBean = listAll.get(position);
        holder.text_title.setText(dataBean.getTitle());
        holder.text_price.setText("价格:" + dataBean.getPrice());

        //0 待支付1 已支付2 已取消
        int status = dataBean.getStatus();
        if (status == 0) {
            holder.text_flag.setText("待支付");
            holder.order_button.setText("取消订单");
        } else if (status == 1) {
            holder.text_flag.setText("已支付");
            holder.order_button.setText("查看订单");
        } else if (status == 2) {
            holder.text_flag.setText("已取消");
            holder.order_button.setText("查看订单");
        }

        holder.text_time.setText("创建时间:" + dataBean.getCreatetime());

        //点击事件
        holder.order_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
        //显示的是 取消订单...取消成功后 显示查看订单,,,flag显示已取消
        if ("取消订单".equals(holder.order_button.getText().toString())) {
            //弹出对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("提示")
                    .setMessage("确定取消订单吗?")
                    .setNegativeButton("否", null)
                    .setPositiveButton("是", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            //请求取消订单的接口,,,成功之后 文字显示改变
                            Map<String, String> params = new HashMap<>();
                            params.put("uid", "2845");
                            params.put("status", String.valueOf(2));
                            params.put("orderId", String.valueOf(dataBean.getOrderid()));
                            RetrofitHelper.getApiService(Api.YU_API).get(Api.UPDATE_ORDER_URL, params)
                                    .subscribeOn(Schedulers.io())
                                    .observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(new Observer<String>() {
                                        @Override
                                        public void onSubscribe(Disposable d) {

                                        }

                                        @Override
                                        public void onNext(String s) {
                                            if ("0".equals(updateOrderBean.getCode())) {
                                                holder.text_flag.setText("已取消");
                                                holder.order_button.setText("查看订单");
                                            }
                                        }

                                        @Override
                                        public void onError(Throwable e) {

                                        }

                                        @Override
                                        public void onComplete() {

                                        }
                                    });
                        }
                    })
                    .show();

                } else {
                    //如果显示查看订单...去查看订单的信息...吐司
                    Toast.makeText(context, "即将跳转查看订单", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return listAll.size();
    }
}


切换的第二个页面(待支付页面)
public class FragmentDaiPayOrder extends Fragment implements FragmentOrderListInter {
    private RecyclerView recyclerView;
    private SmartRefreshLayout smartRefreshLayout;
    private OrderListPresenter orderListPresenter;
    //分页
    private int page = 1;
    //大集合
    private List<OrderListBean.DataBean> listAll = new ArrayList<>();
    private OrderListAdapter orderListAdapter;
    private RelativeLayout relative_empty_order;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
        recyclerView = view.findViewById(R.id.recycler_order);
        smartRefreshLayout = view.findViewById(R.id.smart_refresh);
        relative_empty_order = view.findViewById(R.id.relative_empty_order);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        //获取订单列表的数据
        orderListPresenter = new OrderListPresenter(this);
        orderListPresenter.getOrderData(Api.ORDER_LIST_URL);

        smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                smartRefreshLayout.finishRefresh(2000);
            }
        });
        smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                page ++;
                orderListPresenter.getOrderData(Api.ORDER_LIST_URL);
            }
        });
    }

    /**
     * 设置适配器
     */
    private void setAdapter() {

        if (orderListAdapter == null) {
            orderListAdapter = new OrderListAdapter(getActivity(), listAll);
            recyclerView.setAdapter(orderListAdapter);
        }else {
            orderListAdapter.notifyDataSetChanged();
        }

        smartRefreshLayout.finishLoadmore();
    }
    @Override
    public void onOrderDataSuccess(OrderListBean orderListBean) {
        try {
             if ("0".equals(orderListBean.getCode())) {
                //添加到大集合
                listAll.addAll(orderListBean.getData());

                if (listAll.size() == 0) {
                    relative_empty_order.setVisibility(View.VISIBLE);
                    smartRefreshLayout.setVisibility(View.GONE);
                }else {
                    relative_empty_order.setVisibility(View.GONE);
                    smartRefreshLayout.setVisibility(View.VISIBLE);
                }

                //设置适配器
                setAdapter();

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

}
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_order"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

    <RelativeLayout
        android:visibility="gone"
        android:id="@+id/relative_empty_order"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>qiehuan
切换的第三个页面(已支付)

public class FragmentAlreadyPayOrder extends Fragment implements FragmentOrderListInter {
    private RecyclerView recyclerView;
    private SmartRefreshLayout smartRefreshLayout;
    private OrderListPresenter orderListPresenter;
    //分页
    private int page = 1;
    //大集合
    private List<OrderListBean.DataBean> listAll = new ArrayList<>();
    private OrderListAdapter orderListAdapter;
    private RelativeLayout relative_empty_order;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
        recyclerView = view.findViewById(R.id.recycler_order);
        smartRefreshLayout = view.findViewById(R.id.smart_refresh);
        relative_empty_order = view.findViewById(R.id.relative_empty_order);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        //获取订单列表的数据
        orderListPresenter = new OrderListPresenter(this);
        orderListPresenter.getOrderData(Api.ORDER_LIST_URL);

    }

    /**
     * 设置适配器
     */
    private void setAdapter() {

        if (orderListAdapter == null) {
            orderListAdapter = new OrderListAdapter(getActivity(), listAll);
            recyclerView.setAdapter(orderListAdapter);
        }else {
            orderListAdapter.notifyDataSetChanged();
        }


    }

    @Override
    public void onOrderDataSuccess(OrderListBean orderListBean) {
        try {
             if ("0".equals(orderListBean.getCode())) {
                //添加到大集合
                listAll.addAll(orderListBean.getData());

                if (listAll.size() == 0) {
                    relative_empty_order.setVisibility(View.VISIBLE);
                    smartRefreshLayout.setVisibility(View.GONE);
                }else {
                    relative_empty_order.setVisibility(View.GONE);
                    smartRefreshLayout.setVisibility(View.VISIBLE);
                }

                //设置适配器
                setAdapter();

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

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_order"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

    <RelativeLayout
        android:visibility="gone"
        android:id="@+id/relative_empty_order"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>
第四个页面(已取消)
public class FragmentCacelOrder extends Fragment implements FragmentOrderListInter {
    private RecyclerView recyclerView;
    private SmartRefreshLayout smartRefreshLayout;
    private OrderListPresenter orderListPresenter;
    //分页
    private int page = 1;
    //大集合
    private List<OrderListBean.DataBean> listAll = new ArrayList<>();
    private OrderListAdapter orderListAdapter;
    private RelativeLayout relative_empty_order;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_order_all_layout,container,false);
        recyclerView = view.findViewById(R.id.recycler_order);
        smartRefreshLayout = view.findViewById(R.id.smart_refresh);
        relative_empty_order = view.findViewById(R.id.relative_empty_order);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        //布局管理器
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        //获取订单列表的数据
        orderListPresenter = new OrderListPresenter(this);
        orderListPresenter.getOrderData(Api.ORDER_LIST_URL);

    }

    /**
     * 设置适配器
     */
    private void setAdapter() {

        if (orderListAdapter == null) {
            orderListAdapter = new OrderListAdapter(getActivity(), listAll);
            recyclerView.setAdapter(orderListAdapter);
        }else {
            orderListAdapter.notifyDataSetChanged();
        }


    }

    @Override
    public void onOrderDataSuccess(OrderListBean orderListBean) {
        try {
             if ("0".equals(orderListBean.getCode())) {
                //添加到大集合
                listAll.addAll(orderListBean.getData());

                if (listAll.size() == 0) {
                    relative_empty_order.setVisibility(View.VISIBLE);
                    smartRefreshLayout.setVisibility(View.GONE);
                }else {
                    relative_empty_order.setVisibility(View.GONE);
                    smartRefreshLayout.setVisibility(View.VISIBLE);
                }

                //设置适配器
                setAdapter();

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

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    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">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_order"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

    <RelativeLayout
        android:visibility="gone"
        android:id="@+id/relative_empty_order"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RelativeLayout>

</LinearLayout>

最后:MVP
m层:

public class OrderListModel {
    private OrderListPresenterInter orderListPresenterInter;

    public OrderListModel(OrderListPresenterInter orderListPresenterInter) {
        this.orderListPresenterInter = orderListPresenterInter;
    }

    public void getOrderData(String orderListUrl) {

        Map<String, String> params = new HashMap<>();
        params.put("uid", "2845");
        params.put("page","1");
        RetrofitHelper.getApiService(Api.YU_API).get(orderListUrl, params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        OrderListBean orderListBean = new Gson().fromJson(s, OrderListBean.class);
                        orderListPresenterInter.onOrderDataSuccess(orderListBean);

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}

p层:

public class OrderListPresenter implements OrderListPresenterInter {

    private FragmentOrderListInter fragmentOrderListInter;
    private OrderListModel orderListModel;

    public OrderListPresenter(FragmentOrderListInter fragmentOrderListInter) {
        this.fragmentOrderListInter = fragmentOrderListInter;
        orderListModel = new OrderListModel(this);
    }

    public void getOrderData(String orderListUrl) {

        orderListModel.getOrderData(orderListUrl);

    }

    @Override
    public void onOrderDataSuccess(OrderListBean orderListBean) {
        fragmentOrderListInter.onOrderDataSuccess(orderListBean);
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值