Android仿淘宝订单页面效果

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

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

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

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

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

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

然后创建一个回调接口

代码如下

 public interface OrderContent { public int getLayout(); public boolean isClickable(); public View getView(Context context, View convertView, LayoutInflater inflater); } 

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

第一部分

 public class ItemOrderTop implements OrderContent { private Order order; private OnceSendView2 shopImageView; private List list; private ACache aCache; public ItemOrderTop(Order order, List 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; } }

中间部分

 public class OrderIMiddle implements OrderContent { private Order_goods order_goods; private ImageLoader imageLoader; private DisplayImageOptions options; List order_goodsList; private String status; public OrderIMiddle(Order_goods order_goods, String status) { this.order_goods = order_goods; order_goodsList = new ArrayList(); 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; } }

底部:

 public class OrderBottom implements OrderContent { private Order order; private OnceSendView2 shopImageView; private List list; private ACache aCache; public OrderBottom(Order order, List 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循环将数据循环读入到上中下三个布局中

 //解析后台返回的数据 Type tp = new TypeToken() { }.getType(); OrderItems goodsItem = (OrderItems) ParseUtils.Gson2Object(s, tp); List orderItems = new ArrayList(); orderItems.add(goodsItem); List orderContents; List orderList = new ArrayList(); if (goodsItem.getData() != null) { orderList = goodsItem.getData().getOrders(); orderContents = new ArrayList(); List orderGoodses = new ArrayList(); int totalPages = goodsItem.getData().getPage().getPage_count(); //外部第一个循环,将数据循环读取后存到订单顶部 for (int k = 0; k 

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

以下是Adapter的实现方法

 public class OrderParentListAdapter extends BaseAdapter { private Context context; private List orderContents; private LayoutInflater mIflater; public OrderParentListAdapter(Context context, List orderContents) { this.context = context; if(orderContents!=null) { this.orderContents = orderContents; } else { this.orderContents =new ArrayList(); } } @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 orderContents) { // TODO Auto-generated method stub this.orderContents.addAll(orderContents); this.notifyDataSetChanged(); } public void clearListView() { // TODO Auto-generated method stub this.orderContents.clear(); } } 

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

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

以上就是Android仿淘宝订单页面效果的详细内容,更多请关注html中文网其它相关文章!

赞(0) 打赏
未经允许不得转载:html中文网首页 » 移动

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

1/1