我如何将复选框中的信息保存到Firebase android

问题描述 投票:0回答:1

所以我试图将一些信息保存到Firebase中,到目前为止,我对处理一些文本没有问题,但是我也有一个复选框,我不知道如何处理它,到目前为止,我的想法是使程序查看该复选框是否被“选中”,如果是,则将该复选框ID与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());
                }
            });

[如果您有任何建议或想法如何解决此问题,请先告诉我,谢谢,和平。

java android firebase checkbox android-checkbox
1个回答
0
投票

如果我理解正确,您正在尝试获取复选框的状态并将其提交给firebase,为此,您只需获取复选框的状态并将其另存为布尔值。

Firebase的Guardian复选框和FireBase的Guardian复选框,]

CheckBox c = CheckBox(this)
boolean activa = c.isChecked
© www.soinside.com 2019 - 2024. All rights reserved.