订单列表页

1.订单主页主页面在tablayout中博客里有

里面子页面fragment代码

package com.bwie.skn.moni.indent;

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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bwie.skn.moni.R;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * author:Created by Conan on 2017/12/20.
 */

public class AllFragment extends Fragment implements IIndentListView {
    private View view;
    private XRecyclerView xrecyclerview;
    private List list = new ArrayList<>();
    private XRAdapter xrAdapter;
    private IndentListPresenter indentPresenter;
    private String urlTitle;
    private int page = 1;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.allfragment_layout,container,false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //传的数据
        Bundle bundle = getArguments();
        urlTitle = bundle.getString("url").toString();
        //请求网络
        indentPresenter = new IndentListPresenter(this);
        indentPresenter.excuteSelectCarData(3381,1,urlTitle);
        xrecyclerview = view.findViewById(R.id.xrecyclerview);
        //设置可上拉
        xrecyclerview.setPullRefreshEnabled(true);
        xrecyclerview.setLoadingMoreEnabled(true);
        //设置上拉下拉样式
        xrecyclerview.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        xrecyclerview.setLaodingMoreProgressStyle(ProgressStyle.BallClipRotate);
        // 线性布局管理器   VERTICAL默认样式/竖向显示       第三个参数是数据是否到过来显示
        LinearLayoutManager manager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
        //添加分格线
        xrecyclerview.addItemDecoration(new DividerItemDecoration(getActivity(),LinearLayoutManager.VERTICAL));
        //添加布局管理器
        xrecyclerview.setLayoutManager(manager);
        //设置适配器
        xrAdapter = new XRAdapter(getActivity(), list);
        xrecyclerview.setAdapter(xrAdapter);

        xrecyclerview.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                list.clear();
                indentPresenter.excuteSelectCarData(3381,1,urlTitle);
                xrAdapter.notifyDataSetChanged();
                xrecyclerview.refreshComplete();

            }

            @Override
            public void onLoadMore() {
                page++;
                indentPresenter.excuteSelectCarData(3381,page,urlTitle);
                xrAdapter.notifyDataSetChanged();
                xrecyclerview.loadMoreComplete();
            }
        });
    }

    @Override
    public void onSuccess(List data) {
        list.clear();
        list.addAll(data);

        xrAdapter.notifyDataSetChanged();
        xrecyclerview.loadMoreComplete();
    }

    @Override
    public void onFailed() {

    }
}


2.适配器的使用


package com.bwie.skn.moni.indent;

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.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.skn.moni.R;

import java.util.List;

/**
 * author:Created by Conan on 2017/12/20.
 */

public class XRAdapter extends RecyclerView.Adapter{
    private Context context;
    private List list;

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

    @Override
    public XRAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context,R.layout.indent_item_layout,null);
        view.setMinimumWidth(620);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final XRAdapter.ViewHolder holder, int position) {
        holder.title.setText(list.get(position).getTitle());
        holder.price.setText(list.get(position).getPrice()+"¥");
        holder.createtime.setText(list.get(position).getCreatetime());
        int status = list.get(position).getStatus();
        if (status==0){
            holder.status.setText("待支付");
            holder.indentBtn.setText("取消订单");
        }else if (status==1){
            holder.status.setText("已支付");
            holder.indentBtn.setText("查看订单");
        }else if(status==2){
            holder.status.setText("已取消");
            holder.indentBtn.setText("查看订单");
        }

        holder.indentBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.indentBtn.getText().equals("查看订单")){
                    Toast.makeText(context,"订单已经取消过了",Toast.LENGTH_SHORT).show();
                }else{
                    new AlertDialog.Builder(context)
                            .setTitle("提示")
                            .setMessage("确定是否取消订单")
                            .setNegativeButton("取消", null)//设置取消按钮 null为按钮的点击事件
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {

                                }
                            })//设置确定按钮 null为按钮的点击事件
                            .show();
                }

            }
        });

    }

    @Override
    public int getItemCount() {
        Log.e("IIII",list.size()+"");
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        TextView title;
        TextView price;
        TextView createtime;
        TextView status;
        Button indentBtn;
        public ViewHolder(View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.title);
            price = itemView.findViewById(R.id.price);
            createtime = itemView.findViewById(R.id.createtime);
            status = itemView.findViewById(R.id.status);
            indentBtn = itemView.findViewById(R.id.indentBtn);
        }
    }
}


3.fragment中的布局页面有一个

com.jcodecraeer.xrecyclerview.XRecyclerView

4.适配器中子布局




    
        
        
        
    
    
        
        

5.需要请求网络,获取网络数据,然后在列表中暂时数据,在此不进行演示fragment中的继承的接口为请求网络的接口(MVP请求方式)


你可能感兴趣的:(android)