Exemplo n.º 1
0
  /** 创建直选机选 */
  public void createTable(LinearLayout layout) {
    for (int i = 0; i < balls.size(); i++) {
      final int index = i;
      int iScreenWidth = PublicMethod.getDisplayWidth(this);
      LinearLayout lines = new LinearLayout(layout.getContext());
      for (int j = 0; j < balls.get(i).getVZhuma().size(); j++) {
        String color = (String) balls.get(i).getVColor().get(j);
        TableLayout table;
        if (color.equals("red")) {
          table =
              PublicMethod.makeBallTableJiXuan(
                  null, iScreenWidth, redBallResId, balls.get(i).getBalls(j), this);
        } else {
          table =
              PublicMethod.makeBallTableJiXuan(
                  null, iScreenWidth, blueBallResId, balls.get(i).getBalls(j), this);
        }

        lines.addView(table);
      }
      ImageButton delet = new ImageButton(lines.getContext());
      delet.setBackgroundResource(R.drawable.shanchu);
      delet.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              if (balls.size() > 1) {
                zhumaView.removeAllViews();
                balls.remove(index);
                isOnclik = false;
                jixuanZhu.setSelection(balls.size() - 1);
                createTable(zhumaView);
              } else {
                Toast.makeText(
                        DanshiJiXuan.this,
                        getResources().getText(R.string.zhixuan_jixuan_toast),
                        Toast.LENGTH_SHORT)
                    .show();
              }
            }
          });
      LinearLayout.LayoutParams param =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      param.setMargins(10, 5, 0, 0);
      lines.addView(delet, param);
      lines.setGravity(Gravity.CENTER_HORIZONTAL);
      if (i % 2 == 0) {
        lines.setBackgroundResource(R.drawable.jixuan_list_bg);
      }
      lines.setPadding(0, 3, 0, 0);
      layout.addView(lines);
    }
  }