コード例 #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view = convertView;
    ViewHolder holder = null;
    if (view == null) {
      holder = new ViewHolder();
      view = LayoutInflater.from(context).inflate(R.layout.item_optional, parent, false);
      holder.symbol = (TextView) view.findViewById(R.id.symbol);
      holder.title = (TextView) view.findViewById(R.id.title);
      holder.buyingRate = (TextView) view.findViewById(R.id.buying_rate);
      holder.sellingRate = (TextView) view.findViewById(R.id.selling_rate);
      holder.changeRate = (Button) view.findViewById(R.id.change_rate);
      holder.llOptional = (LinearLayout) view.findViewById(R.id.ll_optional);

      view.setTag(holder);
    } else {
      holder = (ViewHolder) view.getTag();
    }
    Optional optional = items.get(position);
    holder.title.setText(optional.getTitle());
    holder.symbol.setText(optional.getTreaty());
    holder.buyingRate.setText(optional.getBuyone());
    holder.sellingRate.setText(optional.getSellone());
    double diff = 0;
    double diffPercent = 0;
    if (!"".equals(optional.getSellone())
        && null != optional.getSellone()
        && !"".equals(optional.getClosed())
        && null != optional.getClosed()) {
      diff = Double.parseDouble(optional.getSellone()) - Double.parseDouble(optional.getClosed());
      diffPercent = (diff * 100) / Double.parseDouble(optional.getSellone());
    }

    if (diff > 0) {
      holder.changeRate.setBackgroundResource(R.drawable.hongdi);
    } else if (diff == 0) {
      holder.changeRate.setBackgroundResource(R.drawable.huidi);
    } else {
      holder.changeRate.setBackgroundResource(R.drawable.ludi);
    }
    switch (count % 2) {
      case 0:
        holder.changeRate.setText(Utils.getBigDecimal(diffPercent) + "%");
        break;
      case 1:
        holder.changeRate.setText(Utils.getBigDecimal(diff));
        break;

      default:
        break;
    }

    if (diff > 0) {
      holder.llOptional.setBackgroundResource(R.anim.shansuo_red);
      cusRedAnimationDrawable = (AnimationDrawable) holder.llOptional.getBackground();
      cusRedAnimationDrawable.stop();
      cusRedAnimationDrawable.start();

    } else if (diff < 0) {
      holder.llOptional.setBackgroundResource(R.anim.shansuo_green);
      cusGreenAnimationDrawable = (AnimationDrawable) holder.llOptional.getBackground();
      cusGreenAnimationDrawable.stop();
      cusGreenAnimationDrawable.start();
    }

    holder.changeRate.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            count++;
            if (listener != null) listener.change(count);
            notifyDataSetChanged();
          }
        });

    return view;
  }
コード例 #2
0
  @SuppressLint("ResourceAsColor")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view = convertView;
    ViewHolder holder = null;
    if (view == null) {
      view = LayoutInflater.from(context).inflate(R.layout.item_hostory_trade, null);
      holder = new ViewHolder();
      holder.trade_time = (TextView) view.findViewById(R.id.trade_time);
      holder.trade_name = (TextView) view.findViewById(R.id.trade_name);
      holder.trade_value = (TextView) view.findViewById(R.id.trade_value);
      holder.trade_price = (TextView) view.findViewById(R.id.trade_price);
      holder.trade_oritation = (TextView) view.findViewById(R.id.trade_oritation);
      holder.trade_volume = (TextView) view.findViewById(R.id.trade_volume);
      holder.trade_profit = (TextView) view.findViewById(R.id.trade_profit);
      holder.llProfit = (LinearLayout) view.findViewById(R.id.ll_profit);
      view.setTag(holder);
    } else {
      holder = (ViewHolder) view.getTag();
    }

    VirtualTrade trade = items.get(position);

    holder.trade_time.setText(trade.getUpdateTime());

    if (trade.getIsClose() == 1) {
      if (trade.getIsOpening() == 1) {
        if (trade.getOrientation() == 1) {
          holder.trade_oritation.setText("做多");
        } else {
          holder.trade_oritation.setText("做空");
        }

        if (trade.getOrientation() == 1) {
          holder.trade_name.setText(trade.getTitle());
        } else {
          holder.trade_name.setText(trade.getTitle());
        }

      } else {
        holder.trade_oritation.setText("平仓");
        if (trade.getOrientation() == 1) {
          holder.trade_name.setText(
              Html.fromHtml(
                  "<font color='#ff0000'>"
                      + trade.getTitle()
                      + "</font><font color='green'>做多</font>"));
        } else {
          holder.trade_name.setText(
              Html.fromHtml(
                  "<font color='#ff0000'>"
                      + trade.getTitle()
                      + "</font><font color='green'>做空</font>"));
        }
      }

    } else {
      holder.trade_name.setText(trade.getTitle());
      if (trade.getOrientation() == 1) {
        holder.trade_oritation.setText("做多");
      } else {
        holder.trade_oritation.setText("做空");
      }
    }

    if (trade.getIsOpening() == 1 && trade.getIsClose() == 1) {
      holder.trade_value.setText(
          "" + Utils.getFloatDecimal(trade.getTransactionPrice() * trade.getOpenVolume()));
      holder.trade_price.setText("" + trade.getTransactionPrice());
      holder.trade_volume.setText("" + trade.getOpenVolume());
    } else {
      holder.trade_value.setText(
          "" + Utils.getFloatDecimal(trade.getTransactionPrice() * trade.getCloseVolume()));
      holder.trade_price.setText("" + trade.getTransactionPrice());
      holder.trade_volume.setText("" + trade.getCloseVolume());
    }

    if (trade.getIsClose() == 1) {
      if (trade.getIsOpening() == 0) {
        holder.llProfit.setVisibility(View.VISIBLE);
        if (trade.getOrientation() == 1) { // 做多
          float profit =
              (trade.getTransactionPrice() - trade.getOpenPrice()) * trade.getCloseVolume();
          if (profit >= 0) {
            holder.trade_profit.setText(
                Html.fromHtml(
                    "</font><font color='red'>" + Utils.getFloatDecimal(profit) + "</font>"));
          } else {
            holder.trade_profit.setText(
                Html.fromHtml(
                    "</font><font color='green'>" + Utils.getFloatDecimal(profit) + "</font>"));
          }
        } else { // 做空
          float profit =
              (trade.getOpenPrice() - trade.getTransactionPrice()) * trade.getCloseVolume();
          if (profit >= 0) {
            holder.trade_profit.setText(
                Html.fromHtml(
                    "</font><font color='red'>" + Utils.getFloatDecimal(profit) + "</font>"));
          } else {
            holder.trade_profit.setText(
                Html.fromHtml(
                    "</font><font color='green'>" + Utils.getFloatDecimal(profit) + "</font>"));
          }
        }
      } else {
        holder.llProfit.setVisibility(View.GONE);
      }
    } else {
      holder.llProfit.setVisibility(View.GONE);
    }

    return view;
  }