java如何将复选框值传递给动作\u发送
我正在尝试做我的第一个应用程序,我自学了Java,我在2个月前开始使用,所以请原谅我的错误。 我想将复选框的值传递给电子邮件文本,但我认为我需要在发送电子邮件之前刷新“某物”,因为这些值始终为false。。我不知道该怎么办。 代码如下:
public class Appuntamento extends Activity{
String paziente;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appuntamento);
//riceviamo id e lo mettiamo come nome utente
final EditText nomePaziente = (EditText)findViewById(R.id.nomePaziente);
Bundle dati = this.getIntent().getExtras();
nomePaziente.setText(dati.getString("id"));
final String id = dati.getString("id");
EditText noteAppuntamento = (EditText)findViewById(R.id.noteAppuntamento);
final String note = noteAppuntamento.getText().toString();
final CheckBox lunedi = (CheckBox) findViewById(R.id.checkboxLunedi);
final boolean lun = lunedi.isSelected();
final CheckBox martedi = (CheckBox) findViewById(R.id.checkboxMartedì);
final boolean mar = martedi.isSelected();
final CheckBox mercoledi = (CheckBox) findViewById(R.id.checkboxMercoledi);
final boolean mer = mercoledi.isSelected();
final CheckBox giovedi = (CheckBox) findViewById(R.id.checkboxGiovedi);
final boolean giov = giovedi.isSelected();
final CheckBox venerdi = (CheckBox) findViewById(R.id.checkboxVenerdi);
final boolean ven = venerdi.isSelected();
StringBuilder testoMail = new StringBuilder();
if (lun ){
testoMail.append("Lunedì");
} else if (mar){
testoMail.append("Martedì");
}else if (mer) {
testoMail.append("Mercoledì");
} else if (giov) {
testoMail.append("Giovedì");
} else if (ven) {
testoMail.append("Venerdì");
}
final String giorni = testoMail.toString();
Button richiestaAppuntamento = (Button)findViewById(R.id.btnRichiestaAppuntamento);
richiestaAppuntamento.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent mail = new Intent(Intent.ACTION_SEND);
mail.setType("message/rfc822");
mail.putExtra(Intent.EXTRA_SUBJECT, "Richiesta appuntamento");
mail.putExtra(Intent.EXTRA_TEXT, "Nome paziente: " + id + " " + giorni + " " + "Note: " + note);
mail.putExtra(Intent.EXTRA_EMAIL, new String[] {"dottcastellitto@gmail.com"});
startActivity(mail);
}
});
}
}
# 1 楼答案
有两种方法可以做到这一点 像
另一种方式是 像