可以在AlertDialog消息中得到结果吗?

时间:2013-05-15 16:17:53

标签: android message alertdialog

我的计划是有效的。嗯...我在消息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中尝试结果显示,它不起作用。 alertdialog显示,但结果没有。它可以工作吗?

2 个答案:

答案 0 :(得分:0)

这个简单的事情不起作用吗?

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

您实际上是通过此行显示NOTHING

about.setMessage("  ");

所以只需用上面的行替换它。 希望它有所帮助。

答案 1 :(得分:0)

您应该在消息标记中添加字符串值,如下所示:

title.setTitle("RESULT"+showing);
相关问题