@Override
  public void onClick(View view) {
    if (view.getId() == R.id.detail_send) {
      mProgressDialog.show();
      responseString = mEditText.getText().toString();
      sendMessageToServer();
    } else if (view.getId() == R.id.option_reply) {
      final RadioGroup radioGroup = new RadioGroup(MessageDetailActivity.this);
      radioGroup.setBackgroundColor(getResources().getColor(R.color.default_background));
      for (int i = 0; i < options.length; i++) {
        RadioButton radioButton = new RadioButton(this);
        radioButton.setText(options[i]);
        if (i == 0) {
          radioButton.setChecked(true);
          responseString = options[0];
        }
        radioButton.setId(i);
        radioGroup.addView(radioButton);
      }
      radioGroup.setId(-1);
      radioGroup.setOnCheckedChangeListener(
          new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
              responseString = options[checkedId];
            }
          });

      new AlertDialog.Builder(this)
          .setTitle(getString(R.string.reply))
          .setView(radioGroup)
          .setCancelable(false)
          .setPositiveButton(
              getString(R.string.ok),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                  mProgressDialog.show();
                  sendMessageToServer();
                }
              })
          .show();
    }
  }
Beispiel #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout global = new LinearLayout(this); // O layout da janela toda
    global.setOrientation(
        LinearLayout
            .VERTICAL); // Definimos a orientacao que a janela tera(Neste caso sera vertical)

    LinearLayout top = new LinearLayout(this); // O layout da parte de todos os botoes
    top.setOrientation(
        LinearLayout
            .HORIZONTAL); // Definimos a orientacao que a layout tera(Neste caso sera horizontal)

    // Criacao dos 3 botoes
    new TxtButton("Reset", top) {
      void click() {
        clear();
      }
    };
    new TxtButton("Load", top) {
      void click() {
        load();
      }
    };
    new TxtButton("Save", top) {
      void click() {
        save();
      }
    };

    // Criacao dos botoes para escolher a cor
    LinearLayout colorButtons = new LinearLayout(this);

    new ColorButton(Color.RED, colorButtons);
    new ColorButton(Color.GREEN, colorButtons);
    new ColorButton(Color.BLUE, colorButtons);
    new ColorButton(Color.MAGENTA, colorButtons);
    new ColorButton(Color.YELLOW, colorButtons);
    new ColorButton(Color.BLACK, colorButtons);
    new ColorButton(Color.CYAN, colorButtons);

    // Area para colocar os radio buttons
    RadioGroup FigureSelector = new RadioGroup(this);

    // Criacao dos radio buttons
    line = new RadioButton(this);
    line.setText("Line");

    rect = new RadioButton(this);
    rect.setText("Rect");

    circle = new RadioButton(this);
    circle.setText("Circle");

    // Adicionamos os nossos radio buttons ao radio group
    FigureSelector.addView(line);
    FigureSelector.addView(rect);
    FigureSelector.addView(circle);

    // Adicionamos os radiobuttons aos outros botoes
    top.addView(FigureSelector);
    top.addView(new Space(this));
    top.addView(colorButtons);

    drawArea = new DrawArea(this, this);
    // Adicionamos as 2 partes que temos(A parte com todos os botoes, e a parte onde desenhamos
    global.addView(top);
    global.addView(drawArea);

    // Detalhes finais
    line.setChecked(true);
    FigureSelector.setBackgroundColor(Color.GRAY);
    top.setBackgroundColor(Color.GRAY);

    setContentView(global);
  }