dimanche 16 août 2015

How to pass checkbox values to an ACTION_SEND

I'm trying to do my first app, I'm self-taught in Java and I started 2 month ago so please forgive my errors. I want to pass the CheckBoxes values to an email text but I think I need to refresh "something" before sending the email because the values are always false..and I don't know how can I do. Here is the code:

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);
        }
    });

}

}




Aucun commentaire:

Enregistrer un commentaire