Exemplo n.º 1
0
  private void init() {
    cartDao = new CartDao();
    int count = GlobalData.SELECT_COUNT;
    int goodID = GlobalData.SELECT_GOODID;
    Good good = dao.findGoodById(database, goodID);
    goods.addFirst(good);
    adapter = new CartAdapter(goods, context, count);
    lv_cart = (ListView) showView.findViewById(R.id.lv_cart);
    lv_cart.setAdapter(adapter);
    if (goods.size() == 0) {
      // linerlayout_cart_empty.setVisibility(View.VISIBLE);
      // linerlayout_cart_not_empty.setVisibility(View.GONE);
      Toast.makeText(context, "购物车为空,赶紧去逛逛吧!", Toast.LENGTH_SHORT).show();
    } else {
      // linerlayout_cart_empty.setVisibility(View.GONE);
      // linerlayout_cart_not_empty.setVisibility(View.VISIBLE);
      double newprice = good.getNewprice();
      double totalMoney = count * newprice;
      TextView tv_count = (TextView) showView.findViewById(R.id.tv_count);
      TextView tv_totalmoney = (TextView) showView.findViewById(R.id.tv_totalmoney);
      tv_count.setText(count + "");
      tv_totalmoney.setText(totalMoney + "");
      cart = new Cart();
      cart.setSendScore(0);
      cart.setTotalMoney(totalMoney);
      cart.setUserId(GlobalData.LOGIN_SUCCES);
      cart.setGoodId(goodID);
      cart.setCount(count);
      GoodDao goodDao = new GoodDao(context);

      long addGood = cartDao.addGood(database, cart);
      GlobalData.CARTID = addGood;
      // System.out.println(cart.getGoodId());
      if (addGood != -1) {
        Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();
      }
    }
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View view = null;
   ViewHolder holder = null;
   if (convertView != null) {
     view = convertView;
     holder = (ViewHolder) view.getTag();
   } else {
     view = View.inflate(context, R.layout.new_product_item, null);
     holder = new ViewHolder();
     holder.tv_xinpin_name = (TextView) view.findViewById(R.id.tv_xinpin_name);
     holder.iv_xinpin_icon = (ImageView) view.findViewById(R.id.iv_xinpin_icon);
     holder.tv_xinpin_date = (TextView) view.findViewById(R.id.tv_xinpin_date);
     view.setTag(holder);
   }
   Good good = newproducts.get(position);
   holder.tv_xinpin_name.setText(good.getName());
   // 设置显示的图标
   showImage(holder.iv_xinpin_icon, good.getPic());
   holder.tv_xinpin_date.setText(good.getShangjiadate());
   // holder.iv_xinpin_icon.setim
   return view;
 }