91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android如何實現仿淘寶訂單頁面效果

發布時間:2020-07-23 17:38:31 來源:億速云 閱讀:536 作者:小豬 欄目:移動開發

小編這次要給大家分享的是Android如何實現仿淘寶訂單頁面效果,文章內容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。

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

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<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;
 }

}

中間部分

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("&yen;:" + 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("(含運費: &yen; "+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<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的實現方法

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();
 }

}

最后,使用此方法需要和接口溝通好數據返回的格式;

看完這篇關于Android如何實現仿淘寶訂單頁面效果的文章,如果覺得文章內容寫得不錯的話,可以把它分享出去給更多人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

柞水县| 舒城县| 黑河市| 鹤峰县| 会同县| 宁乡县| 嘉兴市| 怀仁县| 九寨沟县| 鄢陵县| 岱山县| 麦盖提县| 丰宁| 昌乐县| 昆山市| 获嘉县| 东城区| 淮安市| 澄江县| 思南县| 博客| 扎兰屯市| 盐城市| 永济市| 兴隆县| 搜索| 鄯善县| 瓮安县| 宁强县| 南华县| 兴宁市| 青冈县| 丰原市| 昭觉县| 大连市| 桓仁| 上犹县| 乾安县| 南溪县| 迁安市| 洪雅县|