0

私のプログラムは仕事です。うーん... メッセージ AlertDialog で結果を表示しようとしましたが、うまくいきませんでした。それは仕事でしょうか?

package diahp.d;



import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;


public class example extends Activity implements OnClickListener {

CheckBox        jimmy,diana,dina,jack;
RadioButton     yes,no;
RadioGroup      radioGroup;
TextView        status;
StringBuilder   showing;
Button show;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.example);

jimmy   = (CheckBox) findViewById(R.id.jimmy);
diana       = (CheckBox) findViewById(R.id.diana);
dina        = (CheckBox) findViewById(R.id.dina);
jack        = (CheckBox) findViewById(R.id.jack);
jimmy.setOnClickListener(this);
diana.setOnClickListener(this);
dina.setOnClickListener(this);
jack.setOnClickListener(this);

yes     = (RadioButton) findViewById(R.id.yes);
no      = (RadioButton) findViewById(R.id.no);
yes.setOnClickListener(this);
no.setOnClickListener(this);

status = (TextView) findViewById(R.id.status);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);

show = (Button) findViewById(R.id.show);
show.setOnClickListener(this);
}

public void onClick(View v) {


    showing  = new StringBuilder();

    if (yes.isChecked())           {
        diana.setEnabled(true);
        jimmy.setEnabled(true);
        dina.setEnabled(true);
        jack.setEnabled(true);      } 

    if(no.isChecked()) {
         diana.setChecked(false);
         jimmy.setChecked(false);
         dina.setChecked(false);
         jack.setChecked(false);
          }

     if(diana.isChecked())
        {showing.append("Diana");}
     if(jimmy.isChecked())
        {showing.append("Jimmy");}
     if(dina.isChecked())
        {showing.append("Dina");}
     if(jack.isChecked())
        {showing.append("Jack");}



     switch (v.getId()) {

     case R.id.show:
            AlertDialog.Builder about = new AlertDialog.Builder(this);
//*******I want this result in pop up alert, could it be?*******************
            status.setText(showing);
//****************************************************
            about.setMessage(" ").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
            }
            });
            AlertDialog title = about.create();
        title.setTitle("RESULT");
        title.setIcon(R.drawable.acon);
        title.show();


}}}

私のプログラムは仕事です。チェックボックスをチェックしたところ、名前のジャックなどの結果が表示されました。うーん...ボタンをクリックしたときにメッセージAlertDialogに結果を表示しようとしましたが、機能しませんでした。アラートダイアログが表示されますが、結果は何もありません。それは仕事でしょうか?

4

2 に答える 2

0

この単純なことは機能しませんか?

about.setMessage("Result is: "+yourResult);

あなたは実際にはこの行で何も表示していません

about.setMessage("  ");

したがって、それを上記の行に置き換えてください。それが役に立てば幸い。

于 2013-05-15T16:29:05.210 に答える
0

以下のように、メッセージタグに文字列値を追加する必要があります。

title.setTitle("RESULT"+showing);
于 2013-05-15T16:29:59.980 に答える