Android仿淘寶訂單頁面效果
一般電商項目會涉及到的訂單管理模塊,類似淘寶樣式的訂單


主要是講一下訂單頁面的實現(xiàn)。當然實現(xiàn)的方法有很多,我知道的有兩種方法:一種是采用listview嵌套listview的方式,這種方式需要重寫listview中onMearsure方法;還有一種是采用接口回調(diào)的方式,這種方式主要對后臺返回的數(shù)據(jù)有依賴;
今天主要說下第二種方法:
實現(xiàn)的思想:首先Tab下面的布局還是用一個listview實現(xiàn),然后將listview中的item分為上中下三部分內(nèi)容;
創(chuàng)建三個xml文件,分別實現(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)分別實現(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("(含運費: ¥ "+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的實現(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- 深入解析Android中的setContentView加載布局原理
- 淺析Android Dialog中setContentView()方法
- Android開發(fā)中setContentView和inflate的區(qū)別分析
- Android開發(fā)微信小程序頁面的圖文教程
- Android 登錄頁面的實現(xiàn)代碼(密碼顯示隱藏、EditText 圖標切換、限制輸入長度)
- Android Studio使用recyclerview實現(xiàn)展開和折疊功能(在之前的微信頁面基礎(chǔ)之上)
- Android Webview的postUrl與loadUrl加載頁面實例
- Android通過ViewModel保存數(shù)據(jù)實現(xiàn)多頁面的數(shù)據(jù)共享功能
- Android仿微信左右滑動點擊切換頁面和圖標
- Android使用setContentView實現(xiàn)頁面的轉(zhuǎn)換效果
相關(guān)文章
Android shell命令行中過濾adb logcat輸出的方法
本文主要介紹Android shell命令行中過濾adb logcat輸出,這里詳細說明了shell 命令過濾logcat 輸出內(nèi)容,有需要的小伙伴可以參考下2016-08-08
Android App開發(fā)的自動化測試框架UI Automator使用教程
UI Automator為Android程序的UI開發(fā)提供了測試環(huán)境,這里我們就來看一下Android App開發(fā)的自動化測試框架UI Automator使用教程,需要的朋友可以參考下2016-07-07
Android TableLayout數(shù)據(jù)列表的回顯清空實現(xiàn)思路及代碼
數(shù)據(jù)列表的回顯必須從后面減去子元素同時必須從后面減去子元素,感興趣的朋友可以看下具體的實現(xiàn)代碼,希望對你學習Android TableLayout有所幫助2013-04-04
Android中使用LayoutInflater要注意的一些坑
LayoutInflater類在我們?nèi)粘i_發(fā)中經(jīng)常會用到,最近在使用中就遇到了一些問題,所有下面這篇文章主要給大家總結(jié)了關(guān)于Android中使用LayoutInflater要注意的一些坑,希望通過這篇能讓大家避免走一些彎路,需要的朋友可以參考學習,下面來一起看吧。2017-04-04
Android利用Camera實現(xiàn)中軸3D卡牌翻轉(zhuǎn)效果
這篇文章主要介紹了Android利用Camera實現(xiàn)中軸3D卡牌翻轉(zhuǎn)效果,需要的朋友可以參考下2015-12-12
簡述Android中實現(xiàn)APP文本內(nèi)容的分享發(fā)送與接收方法
本篇文章主要對Android中實現(xiàn)APP文本內(nèi)容的分享發(fā)送與接收方法進行介紹,相信對大家學習會有很好的幫助,需要的朋友一起來看下吧2016-12-12

