Capture the radio button and save the Text in the bank

1

Galera is able to capture the selected RadioButon to save in the bank, I need to capture the radio button in 3 methods, these 2 radiobutons are in a RadioGroup, the radioButton is the type.

 private Adicionar setAdicionar(Cursor cursor) {
        Adicionar adicionar = new Adicionar();
        adicionar.setId(cursor.getInt(cursor.getColumnIndex("_id")));
        adicionar.setValor(cursor.getString(cursor.getColumnIndex("valor")));
        adicionar.setTipo(cursor.getString(cursor.getColumnIndex("tipo")));
        adicionar.setCategoria(cursor.getString(cursor.getColumnIndex("categoria")));
        adicionar.setData(cursor.getString(cursor.getColumnIndex("data")));
        adicionar.setDescricao(cursor.getString(cursor.getColumnIndex("descricao")));
        return adicionar;
    }
}

And here too I need to get the selected one

private Adicionar lerDadosDoForm(Adicionar adicionar) {
        adicionar.setValor(txtValor.getText().toString());
        adicionar.setCategoria(edtCategoria.getText().toString());
        adicionar.setData(edtData.getText().toString());
        adicionar.setDescricao(edtDescricao.getText().toString());
        adicionar.setTipo(rdbGasto.getText().toString());


        return adicionar;
    }
    
asked by anonymous 30.05.2018 / 21:20

1 answer

1

To get the text of the selected radioButton I use the following code:

RadioButton selecionado;
String situacao;
int idSelecionado = status.getCheckedRadioButtonId(); //pega o id do RadioButton selecionado
selecionado = findViewById(idSelecionado); //Seleciona o RB selecionado pelo id
situacao = String.valueOf(selecionado.getText()); //Pega o texto do RB
    
30.05.2018 / 21:56