##订单列表
//订单
public class DdActivity extends BaseActivity implements IddContract.IddView {
private static final String TAG = "DdActivity";
@BindView(R.id.xrecycler)
XRecyclerView xrecycler;、
@BindView(R.id.radio_butt_qbdd)
RadioButton radioButtQbdd;
@BindView(R.id.radio_butt_dfk)
RadioButton radioButtDfk;
@BindView(R.id.radio_butt_dsh)
RadioButton radioButtDsh;
@BindView(R.id.radio_butt_dpj)
RadioButton radioButtDpj;
@BindView(R.id.radio_butt_ywc)
RadioButton radioButtYwc;
@BindView(R.id.radio_dd)
RadioGroup radioDd;
private IddPresenter presenter;
private Map<String, String> map;
@Override
public int getLayoutId() {
return R.layout.activity_dd;
}
@Override
public void initView() {
ButterKnife.bind(this);
}
@Override
public void initData() {
presenter = new IddPresenter();
presenter.attachView(this);
LoginBeanDao grennDao = GreenDaoUtil.getGrennDao();
List<LoginBean> list = grennDao.queryBuilder().where(LoginBeanDao.Properties.Id.notEq("999"))
.build().list();
LoginBean loginBean = list.get(list.size() - 1);
int userId = loginBean.getUserId();
String sessionId = loginBean.getSessionId();
map = new HashMap<>();
map.put("userId", userId + "");
map.put("sessionId", sessionId);
presenter.getddPresenter(map, "0", "1", "5");
radioDd.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.radio_butt_qbdd:
presenter.getddPresenter(map, "0", "1", "5");
break;
case R.id.radio_butt_dfk:
presenter.getddPresenter(map, "1", "1", "5");
break;
case R.id.radio_butt_dsh:
presenter.getddPresenter(map, "2", "1", "5");
break;
case R.id.radio_butt_dpj:
presenter.getddPresenter(map, "3", "1", "5");
break;
case R.id.radio_butt_ywc:
presenter.getddPresenter(map, "9", "1", "5");
break;
}
}
});
}
@Override
public void onddSuccess(Object data) {
DingDanBean bean = (DingDanBean) data;
Log.i(TAG, "onddSuccess: " + bean.getMessage());
List<DingDanBean.OrderListBean> list = new ArrayList<>();
for (int i = 0; i < bean.getOrderList().size(); i++) {
list.add(bean.getOrderList().get(i));
}
XReclerAdapter xReclerAdapter = new XReclerAdapter(list, DdActivity.this);
xrecycler.setLayoutManager(new LinearLayoutManager(DdActivity.this));
xrecycler.setAdapter(xReclerAdapter);
}
@Override
public void onddFailure(String failure) {
}
}
订单布局
<?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=".DdActivity"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dp_18"
android:background="@drawable/selector_ddxz"
>
<RadioGroup
android:id="@+id/radio_dd"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_70"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/radio_butt_qbdd"
android:layout_width="0dp"
android:layout_height="match_parent"
android:button="@null"
android:layout_weight="1"
android:drawableTop="@drawable/selector_dd_1"
android:paddingTop="@dimen/dp_6"
android:text="全部订单"
android:gravity="center"
/>
<RadioButton
android:id="@+id/radio_butt_dfk"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_dd_2"
android:paddingTop="@dimen/dp_6"
android:text="代付款"
android:gravity="center"
/>
<RadioButton
android:id="@+id/radio_butt_dsh"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:paddingTop="@dimen/dp_6"
android:text="待收货"
android:gravity="center"
android:drawableTop="@drawable/selector_dd_3"
/>
<RadioButton
android:id="@+id/radio_butt_dpj"
android:layout_width="0dp"
android:layout_height="match_parent"
android:button="@null"
android:paddingTop="@dimen/dp_6"
android:text="待评价"
android:gravity="center"
android:layout_weight="1"
android:drawableTop="@drawable/selector_dd_4"
/>
<RadioButton
android:id="@+id/radio_butt_ywc"
android:layout_width="0dp"
android:layout_height="match_parent"
android:button="@null"
android:layout_weight="1"
android:drawableTop="@drawable/selector_dd_5"
android:paddingTop="@dimen/dp_6"
android:text="已完成"
android:gravity="center"
/>
</RadioGroup>
</LinearLayout>
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/xrecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.jcodecraeer.xrecyclerview.XRecyclerView>
</LinearLayout>
//外层适配器(可上拉下拉)
public class XReclerAdapter extends XRecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<DingDanBean.OrderListBean> list;
private Context context;
public XReclerAdapter(List<DingDanBean.OrderListBean> list, Context context) {
this.list = list;
this.context = context;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View inflate = View.inflate(context, R.layout.layout_1, null);
return new MyViewHodel(inflate);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
if (viewHolder instanceof MyViewHodel){
((MyViewHodel) viewHolder).textView_ddh.setText(list.get(i).getOrderId());
((MyViewHodel) viewHolder).recyclerView.setLayoutManager(new LinearLayoutManager(context));
ReclerAdapter01 reclerAdapter01=new ReclerAdapter01(R.layout.layout_2,list.get(i).getDetailList());
((MyViewHodel) viewHolder).recyclerView.setAdapter(reclerAdapter01);
}
}
@Override
public int getItemCount() {
return list.size();
}
class MyViewHodel extends RecyclerView.ViewHolder {
private final TextView textView_ddh;
private final RecyclerView recyclerView;
public MyViewHodel(@NonNull View itemView) {
super(itemView);
textView_ddh=itemView.findViewById(R.id.text_ddh);
recyclerView=itemView.findViewById(R.id.recycler_1);
}
}
}
//子条目(快速适配器)
public class ReclerAdapter01 extends BaseQuickAdapter<DingDanBean.OrderListBean.DetailListBean, BaseViewHolder> {
public ReclerAdapter01(int layoutResId, @Nullable List<DingDanBean.OrderListBean.DetailListBean> data) {
super(layoutResId, data);
}
public ReclerAdapter01(@Nullable List<DingDanBean.OrderListBean.DetailListBean> data) {
super(data);
}
public ReclerAdapter01(int layoutResId) {
super(layoutResId);
}
@Override
protected void convert(BaseViewHolder helper, DingDanBean.OrderListBean.DetailListBean item) {
helper.setText(R.id.text_name,item.getCommodityName());
helper.setText(R.id.text_price,item.getCommodityPrice()+"");
ImageView imageView=helper.getView(R.id.image_1);
String[] split = item.getCommodityPic().split(",");
Glide.with(mContext).load(split[0]).into(imageView);
}
}