服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Android仿淘宝订单页面效果

Android仿淘宝订单页面效果

2022-09-01 13:41Ideaqjjl Android

这篇文章主要介绍了Android仿淘宝订单页面效果,电商项目的订单管理模块,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

一般电商项目会涉及到的订单管理模块,类似淘宝样式的订单

Android仿淘宝订单页面效果

Android仿淘宝订单页面效果

主要是讲一下订单页面的实现。当然实现的方法有很多,我知道的有两种方法:一种是采用listview嵌套listview的方式,这种方式需要重写listview中onMearsure方法;还有一种是采用接口回调的方式,这种方式主要对后台返回的数据有依赖;

今天主要说下第二种方法:

实现的思想:首先Tab下面的布局还是用一个listview实现,然后将listview中的item分为上中下三部分内容;

创建三个xml文件,分别实现三个布局;第一部分为店铺名称那一栏,第二部分为商品信息那一栏,第三部分为订单状态那一栏;

然后创建一个回调接口

代码如下

?
1
2
3
4
5
6
public interface OrderContent
{
public int getLayout();
public boolean isClickable();
public View getView(Context context, View convertView, LayoutInflater inflater);
}

利用接口回调分别实现三个布局

第一部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class ItemOrderTop implements OrderContent {
 private Order order;
 
 private OnceSendView2 shopImageView;
 private List<Order_goods> list;
 private ACache aCache;
 
 public ItemOrderTop(Order order, List<Order_goods> list) {
 
  this.order = order;
  this.list = list;
 }
 
 @Override
 public int getLayout() {
  return R.layout.item_order_top;
 }
 
 @Override
 public boolean isClickable() {
  return true;
 }
 
 public Order order() {
  return order;
 }
 
 @Override
 public View getView(final Context context, View convertView, LayoutInflater inflater) {
  aCache = ACache.get(context);
  inflater = LayoutInflater.from(context);
  convertView = inflater.inflate(getLayout(), null);
 
  final GTextView orderId = (GTextView) convertView.findViewById(R.id.tv_order_num1);
 
  GTextView orderstatus = (GTextView) convertView.findViewById(R.id.tv_order_state1);
 
  orderId.setText("订单号码:" + order.getOrder_sn());
 
 
  switch (order.getStatus().toString()) {
   case "20":
    orderstatus.setText("待发货");
    break;
   case "30":
    orderstatus.setText("已发货");
    break;
   case "40":
    orderstatus.setText("已收货待评价");
    break;
   default:
    break;
 
  }
 
 
  return convertView;
 }
 
}

中间部分

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
public class OrderIMiddle implements OrderContent {
 private Order_goods order_goods;
 private ImageLoader imageLoader;
 private DisplayImageOptions options;
 
 List<Order_goods> order_goodsList;
 private String status;
 
 public OrderIMiddle(Order_goods order_goods, String status) {
  this.order_goods = order_goods;
  order_goodsList = new ArrayList<Order_goods>();
  order_goodsList.add(order_goods);
  this.status = status;
 
  imageLoader = ImageLoader.getInstance();
  // 使用DisplayImageOptions.Builder()创建DisplayImageOptions
  options = new DisplayImageOptions.Builder()
    .showImageOnLoading(R.drawable.publicloading)
    .showImageForEmptyUri(R.drawable.publicloading)
    .showImageOnFail(R.drawable.publicloading)
    .cacheInMemory(true)
    .build();
 
 }
 
 @Override
 public int getLayout() {
  return R.layout.listitem_goods;
 }
 
 @Override
 public boolean isClickable() {
  return true;
 }
 
 public Order_goods order_goods() {
  return order_goods;
 }
 
 @Override
 public View getView(final Context context, View convertView, LayoutInflater inflater) {
 
  inflater = LayoutInflater.from(context);
  convertView = inflater.inflate(getLayout(), null);
 
  GImageView mImage = (GImageView) convertView.findViewById(R.id.iv_goods_image1);
  GTextView goods_info = (GTextView) convertView.findViewById(R.id.tv_goods_info1);
  GTextView goods_attribute = (GTextView) convertView.findViewById(R.id.tv_goods_attribute1);
  GTextView goods_num = (GTextView) convertView.findViewById(R.id.tv_goods_num1);
  GTextView goods_price = (GTextView) convertView.findViewById(R.id.tv_goods_price1);
 
 
  goods_info.setText(order_goods.getGoods_name());
  goods_attribute.setText(order_goods.getSpecification());
  goods_num.setText("x" + order_goods.getQuantity());
  goods_price.setText("¥:" + order_goods.getPrice());
  Log.i("TAG", "order_goods.getOrder_id()=" + order_goods.getOrder_id());
 
 
  imageLoader.init(FileUtils.getCache(context));
 
  imageLoader.displayImage(order_goods.getGoods_image(), mImage, options);
 
  convertView.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    switch (status) {
     case "40":
      Intent intent = new Intent(context, Message_Logistics.class);
      intent.putExtra("order_id", order_goods.getOrder_id());
      context.startActivity(intent);
      break;
     case "30":
      Intent intent2 = new Intent(context, Message_Logistics.class);
      intent2.putExtra("order_id", order_goods.getOrder_id());
      context.startActivity(intent2);
      break;
     case "20":
      Intent intent3 = new Intent(context, Message_Delivery.class);
      intent3.putExtra("order_id", order_goods.getOrder_id());
      context.startActivity(intent3);
      break;
     default:
      break;
    }
 
   }
  });
 
  return convertView;
 }
 
}

底部:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public class OrderBottom implements OrderContent {
 
 private Order order;
 
 private OnceSendView2 shopImageView;
 private List<Order_goods> list;
 private ACache aCache;
 
 public OrderBottom(Order order, List<Order_goods> list) {
 
  this.order = order;
  this.list = list;
 }
 
 @Override
 public int getLayout() {
  return R.layout.item_list_list;
 }
 
 @Override
 public boolean isClickable() {
  return true;
 }
 
 public Order order() {
  return order;
 }
 
 @Override
 public View getView(final Context context, View convertView, LayoutInflater inflater) {
  aCache = ACache.get(context);
  inflater = LayoutInflater.from(context);
  convertView = inflater.inflate(getLayout(), null);
 
  GTextView orderTotal = (GTextView) convertView.findViewById(R.id.tv_order_amount1);
  GTextView tv_order_datetime = (GTextView) convertView.findViewById(R.id.tv_order_datetime);
  final GButton oncesend = (GButton) convertView.findViewById(R.id.btn_send1);
  GTextView yunfei_text = (GTextView) convertView.findViewById(R.id.yunfei_text);
 
  yunfei_text.setText("(含运费: ¥ "+order.getShipping_fee()+")");
 
  orderTotal.setText(order.getOrder_amount());
  tv_order_datetime.setText(Data_Time.getDateToString(order.getAdd_time()));
  final View finalConvertView = convertView;
  if (order.getStatus().equals("20")) {
   oncesend.setText("立即发货");
 
 
   oncesend.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
 
     Intent otherintent = new Intent(context, Message_Delivery.class);
     otherintent.putExtra("order_id", order.getOrder_id());
     otherintent.putExtra("token", aCache.getAsString("token"));
     context.startActivity(otherintent);
    }
   });
  } else if (order.getStatus().equals("30")){
   oncesend.setBackgroundResource(R.color.highlight_color);
   oncesend.setText("查看物流");
   oncesend.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
     Intent intent = new Intent(context, Message_Logistics.class);
     intent.putExtra("order_id", order.getOrder_id());
     context.startActivity(intent);
    }
   });
 
  }
  else
  {
   oncesend.setVisibility(View.GONE);
 
  }
 
  return convertView;
 }
 
 
}

接收接口返回的数据,然后利用for循环将数据循环读入到上中下三个布局中

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//解析后台返回的数据
  Type tp = new TypeToken<OrderItems>() {
  }.getType();
  OrderItems goodsItem = (OrderItems) ParseUtils.Gson2Object(s, tp);
  List<OrderItems> orderItems = new ArrayList<OrderItems>();
 
  orderItems.add(goodsItem);
  List<OrderContent> orderContents;
  List<Order> orderList = new ArrayList<Order>();
 
  if (goodsItem.getData() != null) {
   orderList = goodsItem.getData().getOrders();
   orderContents = new ArrayList<OrderContent>();
   List<Order_goods> orderGoodses = new ArrayList<Order_goods>();
   int totalPages = goodsItem.getData().getPage().getPage_count();
 
   //外部第一个循环,将数据循环读取后存到订单顶部
   for (int k = 0; k < orderList.size(); k++) {
    orderGoodses = orderList.get(k).getOrder_goods();
    Order ordertop = new Order();
    ordertop.setOrder_sn(orderList.get(k).getOrder_sn());
    ordertop.setStatus(orderList.get(k).getStatus());
    ordertop.setEvaluation_status(orderList.get(k).getEvaluation_status());
    ItemOrderTop itemOrderTop = new ItemOrderTop(ordertop, orderGoodses);
    orderContents.add(itemOrderTop);
 
    if (orderGoodses == null) {
     BaseUtil.showToast(context, "没有订单");
    } else {
     //中间for循环,将数据循环读取后存到订单中间部分
     for (int j = 0; j < orderGoodses.size(); j++) {
      Order_goods goods = new Order_goods();
      goods.setPrice(orderGoodses.get(j).getPrice());
      goods.setGoods_name(orderGoodses.get(j).getGoods_name());
      goods.setQuantity(orderGoodses.get(j).getQuantity());
      goods.setGoods_image(orderGoodses.get(j).getGoods_image());
      goods.setSpecification(orderGoodses.get(j).getSpecification());
      goods.setOrder_id(orderGoodses.get(j).getOrder_id());
      OrderIMiddle orderIMiddle = new OrderIMiddle(goods,  orderList.get(k).getStatus());
      orderContents.add(orderIMiddle);
      Log.i("myLog", "orderContents =" + orderContents);
     }
    }
    //外部第二个循环,将数据循环读取后存到订单底部
    Order order = new Order();
    order.setOrder_sn(orderList.get(k).getOrder_sn());
    order.setOrder_id(orderList.get(k).getOrder_id());
    order.setStatus(orderList.get(k).getStatus());
    order.setAdd_time(orderList.get(k).getAdd_time());
    order.setOrder_amount(orderList.get(k).getOrder_amount());
    order.setShipping_fee(orderList.get(k).getShipping_fee());
    OrderBottom orderBottom = new OrderBottom(order, orderGoodses);
    orderContents.add(orderBottom);
 
   }
   mUpdateListview(orderContents, mOrderAdapter, mListView, page, totalPages);
 
  } else {
   BaseUtil.showToast(context, "没有订单");
  }
}

然后利用setAdapter方法将数据传到Adapter中。

以下是Adapter的实现方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class OrderParentListAdapter extends BaseAdapter {
 
 private Context context;
 private List<OrderContent> orderContents;
 private LayoutInflater mIflater;
 
 public OrderParentListAdapter(Context context, List<OrderContent> orderContents) {
  this.context = context;
  if(orderContents!=null)
  {
   this.orderContents = orderContents;
 
  }
  else
  {
   this.orderContents =new ArrayList<OrderContent>();
 
  }
 
 }
 
 @Override
 public int getCount() {
  return orderContents.size();
 }
 
 @Override
 public Object getItem(int position) {
  return orderContents.get(position);
 }
 
 @Override
 public long getItemId(int position) {
  return position;
 }
 
 @Override
 public boolean isEnabled(int position) {
  // TODO Auto-generated method stub
  return orderContents.get(position).isClickable();
 }
 
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  return orderContents.get(position).getView(context,convertView,mIflater);
 }
 
 public void upateList(List<OrderContent> orderContents) {
  // TODO Auto-generated method stub
  this.orderContents.addAll(orderContents);
  this.notifyDataSetChanged();
 }
 
 public void clearListView() {
  // TODO Auto-generated method stub
  this.orderContents.clear();
 }
 
}

最后,使用此方法需要和接口沟通好数据返回的格式;

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/Ideaqjjl/article/details/51043644

延伸 · 阅读

精彩推荐