How to make a button write data from a form with click events

1

I have a form and wish to save it when the save button is pressed, the solution I did is not working.

public class SalvarFormulario extends AppCompatActivity {


EditText Nome;
EditText edtTelefone;
EditText edtObservacao;
EditText edtEmail;
Button btSalvar;


FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_formulario);


    Nome = (EditText) findViewById(R.id.Nome);
    edtEmail = (EditText) findViewById(R.id.edtEmail);
    edtObservacao = (EditText) findViewById(R.id.edtObservacao);
    edtTelefone = (EditText) findViewById(R.id.edtTelefone);
    btSalvar = (Button) findViewById(R.id.btSalvar);






    InicializaFirebase();
    SalvarDados(); // <--- salva os dados 
}




private void InicializaFirebase() {
    FirebaseApp.initializeApp(SalvarFormulario.this);
    firebaseDatabase = FirebaseDatabase.getInstance();
    databaseReference = firebaseDatabase.getReference();
}

private void limparCampos() {
    Nome.setText("");
    edtTelefone.setText("");
    edtObservacao.setText("");
    edtEmail.setText("");

}
    
asked by anonymous 03.10.2017 / 03:55

1 answer

0

You have to get your button and use the setOnClickListener method and there you call the method responsible for saving the data, like this:

         botao.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             salvarDados();
         }
     });
    
03.10.2017 / 04:17