(1)利用 button與AlertDialog結合利用
package COM.TQC.GDD01; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; public class GDD01 extends Activity { private EditText et; private RadioButton rb1; private RadioButton rb2; private CheckBox cb1; private CheckBox cb2; private CheckBox cb3; private Button button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); et = (EditText) findViewById(R.id.name); rb1 = (RadioButton) findViewById(R.id.rButton1); rb2 = (RadioButton) findViewById(R.id.rButton2); cb1 = (CheckBox) findViewById(R.id.cBox1); cb2 = (CheckBox) findViewById(R.id.cBox2); cb3 = (CheckBox) findViewById(R.id.cBox3); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ String s=""; String b =""; if(!et.getText().toString().equals("")){ s += "姓名:"+et.getText().toString()+"\n"; }else{ s += "姓名:未填\n"; } if(rb1.isChecked()){ s +="性別:"+rb1.getText().toString()+"\n"; }else{ s +="性別:"+rb2.getText().toString()+"\n"; } if(cb1.isChecked()){ b +=cb1.getText().toString()+","; } if(cb2.isChecked()){ b +=cb3.getText().toString()+","; } if(cb3.isChecked()){ b +=cb2.getText().toString()+","; } if(!b.equals("")){ s += "興趣:" + b; }else{ s += "興趣:未選擇"; } new AlertDialog.Builder(GDD01.this) .setTitle("結果") .setMessage(s) .setPositiveButton("離開", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // TODO Auto-generated method stub } }) .show(); } }); } }
沒有留言:
張貼留言