2
I have a form and wish to save it when the button is pressed salvage, the solution I made 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("");
}
You must create the method
SalvarDados()
if it hasn’t been created yet, you can’t tell because the code isn’t complete.– NoobSaibot
already created: public void Save Data() { // if (btSalvar.isSelected()) { Register c = new Register(); c.setuid(UUID.randomUUID().toString(); c.setName(Name.gettext().toString(); c.setTelephone(edtTelephone.gettext().toString(); c.setEmail(edtEmail.gettext().toString()); c.setObservation(edtObservation.gettext().toString()); databaseReference.Child("Registration"). Child(c.getUid()). setValue(c); cleanCampos(); }
– Junior Machado
Then see if the answer given by @Natanfelipe solves your question.
– NoobSaibot