Android_展示状态

将订单的状态展示出来
model层

public class IndentListModel {
    private HashMap<String, String> map = new HashMap<>();
    public void verifySelectCarInfo(int uid,int page,String urlTitle, final IIndentListPresenter iIndentPresenter){
        map.put("uid",uid+"");
        map.put("page",page+"");
        if ("4".equals(urlTitle)){

        }else{
            map.put("status",urlTitle);
        }
        OkHttpUtils.getInstance().doGet("http://120.27.23.105/product/getOrders", map, new CallBack() {

            @Override
            public void onFailed(String msg) {
                iIndentPresenter.onFailed();
            }

            @Override
            public void onSuccess(String request) {
                IndentListBean indentBean = GsonUtils.getInstance().fromJson(request, IndentListBean.class);
                String code = indentBean.getCode();
                if ("0".equals(code)){
                    List<IndentListBean.DataBean> data = indentBean.getData();
                    iIndentPresenter.onSuccess(data);
                }else {
                    iIndentPresenter.onFailed();
                }
            }
        });
    }
}

接口

public interface IIndentListPresenter {
    void onSuccess(List<IndentListBean.DataBean> data);

    void onFailed();
}

public interface IIndentListView {
    void onSuccess(List<IndentListBean.DataBean> data);

    void onFailed();
}

presenter层

public class IndentListPresenter implements IIndentListPresenter {
    private IIndentListView iIndentView;
    private IndentListModel indentModel;

    public IndentListPresenter(IIndentListView iIndentView){
        this.iIndentView = iIndentView;
        indentModel = new IndentListModel();
    }

    //执行集合信息
    public void excuteSelectCarData(int uid,int page,String urlTitle){
        //传到model
        indentModel.verifySelectCarInfo(uid,page,urlTitle,this);
    }
    @Override
    public void onSuccess(List<IndentListBean.DataBean> data) {
        iIndentView.onSuccess(data);
    }

    @Override
    public void onFailed() {
        iIndentView.onFailed();
    }
}

view层

public class IndentListActivity extends AppCompatActivity {
    private TabLayout tl;
    private ViewPager vp;
    private List<String> datas = new ArrayList<String>();
    private String[] status = new String[]{"4","0","1","2"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_indent_list);

        tl = (TabLayout) findViewById(R.id.tl);
        vp = (ViewPager) findViewById(R.id.vp);

        datas.add("全部");
        datas.add("待支付");
        datas.add("已支付");
        datas.add("已取消");

        vp.setAdapter(new MyAdapter(getSupportFragmentManager()));
        //进行关联
        tl.setupWithViewPager(vp);
    }
    class MyAdapter extends FragmentPagerAdapter {
        //带参的构造方法
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public int getCount() {
            return datas.size();
        }

        //返回选项卡的文本 ,,,添加选项卡
        @Override
        public CharSequence getPageTitle(int position) {
            return datas.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            //创建fragment对象并返回
            Bundle bundle = new Bundle();
            bundle.putString("url", status[position]);
            //实例化Fragment
            AllFragment allFragment = new AllFragment();
            allFragment.setArguments(bundle);
            return allFragment;
        }
    }

}

view的布局

<RelativeLayout 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.jkr.moni2.indent.IndentListActivity">
    <android.support.design.widget.TabLayout
        android:id="@+id/tl"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/colorAccent"
        app:tabMode="fixed"

        app:tabTextColor="@color/colorPrimary"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tl"
        ></android.support.v4.view.ViewPager>
</RelativeLayout>

适配器

public class XRAdapter extends RecyclerView.Adapter<XRAdapter.ViewHolder>{
    private Context context;
    private List<IndentListBean.DataBean> list;

    public XRAdapter(Context context, List<IndentListBean.DataBean> 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);
        }
    }
}

适配器的布局

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="7"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="订单测试标题3381"
            />
        <TextView
            android:id="@+id/price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="价格:1.10¥"
            />
        <TextView
            android:id="@+id/createtime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0000-00-00T00:00:00"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="3"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <TextView
            android:id="@+id/status"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="未支付"

            />
        <Button
            android:id="@+id/indentBtn"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:text="取消订单"
            />
    </LinearLayout>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值