adapter
public class MyAdapter extends RecyclerView.Adapter{
Context context;
List<DataDataBean.DataBean> data;
public MyAdapter(Context context, List<DataDataBean.DataBean> data) {
this.context = context;
this.data = data;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = View.inflate(context, R.layout.fragmentone_item,null);
return new ViewHolder1(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
ViewHolder1 holder1 = (ViewHolder1) holder;
holder1.time.setText("创建时间:"+data.get(position).getCreatetime());
holder1.title.setText(data.get(position).getTitle());
holder1.price.setText("价格:"+data.get(position).getPrice()+"");
if(data.get(position).getStatus() ==0){
holder1.textView.setTextColor(Color.RED);
holder1.btn.setText("取消订单");
holder1.textView.setText("待支付");
}else if(data.get(position).getStatus()==1){
holder1.btn.setText("查看订单");
holder1.textView.setText("已支付");
}else{
holder1.btn.setText("已取消");
holder1.textView.setText("查看订单");
}
//点击事件,接口回调
holder1.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(setStatus!=null){
setStatus.getStatus(data.get(position).getStatus()+"",data.get(position).getOrderid()+"");
notifyDataSetChanged();
}
}
});
}
SetStatus setStatus;
public void setChangeStatus(SetStatus setStatus){
this.setStatus = setStatus;
}
//点击接口回调
public interface SetStatus{
void getStatus(String status,String id);
}
@Override
public int getItemCount() {
return data.size();
}
class ViewHolder1 extends RecyclerView.ViewHolder {
TextView title;
TextView price;
Button btn;
TextView textView;
TextView time;
public ViewHolder1(View itemView) {
super(itemView);
time = itemView.findViewById(R.id.timeGreate);
title = itemView.findViewById(R.id.titleIt);
price = itemView.findViewById(R.id.price);
btn = itemView.findViewById(R.id.btn);
textView = itemView.findViewById(R.id.textview);
}
}
}
public class MyViewpagerAdapter extends FragmentPagerAdapter{
List<Fragment> data;
public MyViewpagerAdapter(FragmentManager fm, List<Fragment> data) {
super(fm);
this.data=data;
}
@Override
public Fragment getItem(int position) {
return data.get(position);
}
@Override
public int getCount() {
return data.size();
}
}
bean
public class DataChangeBean {
/**
* msg : 订单状态修改成功
* code : 0
*/
private String msg;
private String code;
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 class DataDataBean {
/**
* msg : 请求成功
* code : 0
* data : [{"createtime":"2017-10-19T20:28:43","orderid":20,"price":100,"status":2,"title":"订单标题测试3","uid":71},{"createtime":"2017-10-19T20:44:40","orderid":31,"price":11800,"status":2,"title":"订单标题测试14","uid":71},{"createtime":"2017-10-19T20:44:51","orderid":32,"price":11800,"status":1,"title":"订单标题测试15","uid":71},{"createtime":"2017-10-20T08:02:07","orderid":43,"price":11800,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-10-20T08:02:16","orderid":44,"price":11800,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-10-22T15:14:39","orderid":890,"price":11800,"status":2,"title":"","uid":71},{"createtime":"2017-11-09T09:17:20","orderid":1446,"price":99.99,"status":1,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1447,"price":567,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1448,"price":256.99,"status":2,"title":"订单标题测试","uid":71},{"createtime":"2017-11-09T09:20:58","orderid":1449,"price":399,"status":2,"title":"订单标题测试","uid":71}]
* page : 1
*/
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 {
/**
* createtime : 2017-10-19T20:28:43
* orderid : 20
* price : 100.0
* status : 2
* title : 订单标题测试3
* uid : 71
*/
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;
}