Android仿淘寶訂單頁面效果
一般電商項(xiàng)目會涉及到的訂單管理模塊,類似淘寶樣式的訂單
主要是講一下訂單頁面的實(shí)現(xiàn)。當(dāng)然實(shí)現(xiàn)的方法有很多,我知道的有兩種方法:一種是采用listview嵌套listview的方式,這種方式需要重寫listview中onMearsure方法;還有一種是采用接口回調(diào)的方式,這種方式主要對后臺返回的數(shù)據(jù)有依賴;
今天主要說下第二種方法:
實(shí)現(xiàn)的思想:首先Tab下面的布局還是用一個listview實(shí)現(xiàn),然后將listview中的item分為上中下三部分內(nèi)容;
創(chuàng)建三個xml文件,分別實(shí)現(xiàn)三個布局;第一部分為店鋪名稱那一欄,第二部分為商品信息那一欄,第三部分為訂單狀態(tài)那一欄;
然后創(chuàng)建一個回調(diào)接口
代碼如下
public interface OrderContent { public int getLayout(); public boolean isClickable(); public View getView(Context context, View convertView, LayoutInflater inflater); }
利用接口回調(diào)分別實(shí)現(xiàn)三個布局
第一部分
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("待發(fā)貨"); break; case "30": orderstatus.setText("已發(fā)貨"); 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_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()創(chuàng)建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<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("(含運(yùn)費(fèi): ¥ "+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("立即發(fā)貨"); 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; } }
接收接口返回的數(shù)據(jù),然后利用for循環(huán)將數(shù)據(jù)循環(huán)讀入到上中下三個布局中
//解析后臺返回的數(shù)據(jù) 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(); //外部第一個循環(huán),將數(shù)據(jù)循環(huán)讀取后存到訂單頂部 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循環(huán),將數(shù)據(jù)循環(huán)讀取后存到訂單中間部分 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); } } //外部第二個循環(huán),將數(shù)據(jù)循環(huán)讀取后存到訂單底部 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方法將數(shù)據(jù)傳到Adapter中。
以下是Adapter的實(shí)現(xiàn)方法
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(); } }
最后,使用此方法需要和接口溝通好數(shù)據(jù)返回的格式;
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 深入解析Android中的setContentView加載布局原理
- 淺析Android Dialog中setContentView()方法
- Android開發(fā)中setContentView和inflate的區(qū)別分析
- Android開發(fā)微信小程序頁面的圖文教程
- Android 登錄頁面的實(shí)現(xiàn)代碼(密碼顯示隱藏、EditText 圖標(biāo)切換、限制輸入長度)
- Android Studio使用recyclerview實(shí)現(xiàn)展開和折疊功能(在之前的微信頁面基礎(chǔ)之上)
- Android Webview的postUrl與loadUrl加載頁面實(shí)例
- Android通過ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁面的數(shù)據(jù)共享功能
- Android仿微信左右滑動點(diǎn)擊切換頁面和圖標(biāo)
- Android使用setContentView實(shí)現(xiàn)頁面的轉(zhuǎn)換效果
相關(guān)文章
Android使用個推實(shí)現(xiàn)三方應(yīng)用的推送功能
這篇文章主要為大家詳細(xì)介紹了Android使用個推實(shí)現(xiàn)三方應(yīng)用的推送功能,感興趣的小伙伴們可以參考一下2016-08-08Android之帶group指示器的ExpandableListView(自寫)
Android缺省的ExpandableListView的group header無法固定在界面上,在網(wǎng)上搜索了好多都不盡人意,于是乎在別人的基礎(chǔ)上改進(jìn)了一點(diǎn)點(diǎn),原理都差不多2013-06-06Android6.0獲取GPS定位和獲取位置權(quán)限和位置信息的方法
今天小編就為大家分享一篇Android6.0獲取GPS定位和獲取位置權(quán)限和位置信息的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07Android手機(jī)信號強(qiáng)度檢測詳細(xì)介紹
這篇文章主要介紹了Android手機(jī)信號強(qiáng)度檢測的相關(guān)資料,android定義了2種信號單位:dBm和asu。具體兩種的關(guān)系本文給大家介紹非常詳細(xì),需要的朋友可以參考下2016-11-11Android--SQLite(增,刪,改,查)操作實(shí)例代碼
Android--SQLite(增,刪,改,查)操作實(shí)例代碼,需要的朋友可以參考一下2013-02-02Android編程獲取APP應(yīng)用程序基本信息輔助類【APP名稱、包名、圖標(biāo),版本號等】
這篇文章主要介紹了Android編程獲取APP應(yīng)用程序基本信息輔助類,可實(shí)現(xiàn)針對APP名稱、包名、圖標(biāo),版本號等信息的獲取功能,需要的朋友可以參考下2017-12-12android中Activity詳解(生命周期、以各種方式啟動Activity、狀態(tài)保存,完全退出等)
本篇文章詳細(xì)的介紹了Activity,包括生命周期、以各種方式啟動Activity、狀態(tài)保存,完全退出等,有興趣的可以了解一下。2016-11-11A10_DatePicker的對話框設(shè)置(使用OnDateSetListener監(jiān)聽器)
本文主要彌補(bǔ)A07_TimePicker & DatePicker & AnalogClock & DigitalClock 的設(shè)置,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下哈2013-06-06