vendredi 20 mars 2020

How can i save information from a checkbox to firebase android

So im trying to save some information into firebase, and so far i´ve no problem with dealing with some text, but i also have a checkbox and i dont know how to deal with it, so far my idea is to make the program see if the checkbox is "checked" and if so, then associate that checkbox id to mi "txtRamos".

    txtEvento = findViewById(R.id.pop_nombre_evento);
    txtHrInico = findViewById(R.id.tiempo_inicio);
    txtHrTermino = findViewById(R.id.tiempo_termino);
    txtLugar = findViewById(R.id.pop_info_lugar);

    mat021 = (CheckBox) findViewById(R.id.Mat021);
    mat022 = (CheckBox) findViewById(R.id.mat022);
    mat023 = (CheckBox) findViewById(R.id.mat023);
    mat024 = (CheckBox) findViewById(R.id.mat024);
    fis100 = (CheckBox) findViewById(R.id.fis100);
    fis110 = (CheckBox) findViewById(R.id.fis110);
    fis120 = (CheckBox) findViewById(R.id.fis120);
    fis130 = (CheckBox) findViewById(R.id.fis130);
    iwg101 = (CheckBox) findViewById(R.id.iwg101);
    iwi131 = (CheckBox) findViewById(R.id.iwi131);
    qui010 = (CheckBox) findViewById(R.id.qui010);

    if (mat021.isChecked()) {

    }
}

public void saveNote(View v) {

    String evento_tittle = txtEvento.getText().toString();
    String hr_inicio = txtHrInico.getText().toString();
    String hr_termino = txtHrTermino.getText().toString();
    String lugar = txtLugar.getText().toString();
    String ramo = txtRamo.getText().toString();

    Map<String, Object> note = new HashMap<>();
    note.put(KEY_N_EVENTO, evento_tittle);
    note.put(KEY_INICIO, hr_inicio);
    note.put(KEY_TERMINO, hr_termino);
    note.put(KEY_INFO_LUGAR, lugar);
    note.put(KEY_RAMO, ramo);

    db.collection("eventos").document().set(note)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Toast.makeText(pop_eventos.this, "Evento Guardado", Toast.LENGTH_SHORT).show();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(pop_eventos.this, "Error al guardar evento", Toast.LENGTH_SHORT).show();
                    Log.d(TAG, e.toString());
                }
            });

Please if you have any advice or idea how to deal with this, tell me, thanks in advance, peace.




Aucun commentaire:

Enregistrer un commentaire