0
wanted to know how I took the value of a Radiobutton to save it in the sqlite bank. In the example below the instructor does as follows:
public class FormularioHelper {
private Aluno aluno;
public FormularioHelper(FormularioActivity activity) {
campoNome = (EditText) activity.findViewById(R.id.formulario_nome);
campoEndereco = (EditText) activity.findViewById(R.id.formulario_endereco);
campoTelefone = (EditText) activity.findViewById(R.id.formulario_telefone);
campoSite = (EditText) activity.findViewById(R.id.formulario_site);
campoNota = (RatingBar) activity.findViewById(R.id.formulario_nota);
campoFoto = (ImageView) activity.findViewById(R.id.formulario_foto);
aluno = new Aluno();
}
public Aluno pegaAluno() {
aluno.setNome(campoNome.getText().toString());
aluno.setEndereco(campoEndereco.getText().toString());
aluno.setTelefone(campoTelefone.getText().toString());
aluno.setSite(campoSite.getText().toString());
aluno.setNota(Double.valueOf(campoNota.getProgress()));
aluno.setCaminhoFoto((String) campoFoto.getTag());
return aluno;
}}
Mine is partially like this:
public class FormularioProcessoHelper {
private ImageView ivCaminhoFoto;
private Spinner spPromotores;
private RadioButton rbFavoravel;
private RadioButton rbDesfavoravel;
private RadioGroup radioGroup;
private EditText edtObservacao;
private Button btnDataProcesso;
private Processo processo;
public FormularioProcessoHelper(FormularioProcessoActivity activity) {
ivCaminhoFoto = (ImageView) activity.findViewById(R.id.iv_foto_selecionada);
spPromotores = (Spinner) activity.findViewById(R.id.spinner_promotores);
rbFavoravel = (RadioButton) activity.findViewById(R.id.posicao_judicial_favoravel);
rbDesfavoravel = (RadioButton) activity.findViewById(R.id.posicao_judicial_desfavoravel);
edtObservacao = (EditText) activity.findViewById(R.id.edt_observacao);
btnDataProcesso = (Button) activity.findViewById(R.id.btn_data);
processo = new Processo();
}
public Processo pegaProcessoPraCadastro() {
Processo processo = new Processo();
processo.setCaminhoFoto((String) ivCaminhoFoto.getTag());
processo.setPosicao(radioGroup.); // AQUI, QUERIA PEGAR O VALOR DO RADIOBUTTON SELECIONADO
processo.setPromotor(spPromotores.getSelectedItemPosition()); //AQUI --//-- SPINNER SELECIONADO
processo.setDataProcesso(btnDataProcesso.PegarAData()); // AQUI --//-- A DATA SETADA PELO USUARIO
processo.setObservacao(edtObservacao.getText().toString());
return processo;
}
}
The problem is, I didn’t find the methods to get these values. Both Spinner and Radiobutton’s. The commented lines are where the bugs are!
My Model Class Process:
public class Processo implements Serializable {
private Long id;
private String caminhoFoto;
private Usuario promotor;
private String observacao;
private String dataProcesso;
private PosicaoJudiciario posicao;
public Usuario getPromotor() {
return promotor;
}
public void setPromotor(Usuario promotor) {
this.promotor = promotor;
}
public String getObservacao() {
return observacao;
}
public void setObservacao(String observacao) {
this.observacao = observacao;
}
public String getDataProcesso() {
return dataProcesso;
}
public void setDataProcesso(String dataProcesso) {
this.dataProcesso = dataProcesso;
}
public PosicaoJudiciario getPosicao() {
return posicao;
}
public void setPosicao(PosicaoJudiciario posicao) {
this.posicao = posicao;
}
public String getCaminhoFoto() {
return caminhoFoto;
}
public void setCaminhoFoto(String caminhoFoto) {
this.caminhoFoto = caminhoFoto;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return "Nome: " + getPromotor();
}
}
My User Model Class:
public class Usuario implements Serializable{
private String nome;
private String senha;
private String email;
private String matricula;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMatricula() {
return matricula;
}
public void setMatricula(String matricula) {
this.matricula = matricula;
}
}
Says Edson, all right? So this part helped, but I wanted to know how I saved in the bank, using that method of mine up there.
– Eduardo Maxwell
In device database? You can use Sharedpreferences.
– Edson Reis
I edited my answer, see if it helps you.
– Edson Reis
You want to save the object, radiogroup position or selected value?
– Edson Reis
I want to save its value, it can be either its ID or its Text. Saving in the bank, ta of good size.
– Eduardo Maxwell
came to test the example that I complemented the up? it saves in the internal bank.
– Edson Reis