How to save form in android studio and send pro firebase

0

I have a simple form, with name, surname and age. I want to send the data typed in the editText of this form to the firebase. The solutions found in the smp web are referring to login forms which leaves the code very complex.

I have already created the json file in the firebase named person and the "name", "surname" and "old" node should receive the values from the formulary ... if anyone can guide me on how to do this I appreciate it.

    
asked by anonymous 26.09.2017 / 18:20

1 answer

1

You can do the following: Catch the firebase reference:

mDatabase = FirebaseDatabase.getInstance().getReference();

Then create the fields in which the data will be inserted:

    nomeEdit = (EditText) findViewById(R.id.field_nome);
    sobrenomeEdit = (EditText) findViewById(R.id.field_sobrenome);
    idadeEdit = (EditText) findViewById(R.id.field_idade);

Take what was typed in these fields:

    final String nome = nomeEdit.getText().toString();
    final String sobrenome = sobrenomeEdit.getText().toString();
    final String idade = idadeEdit.getText().toString();

Then you can use a Map to insert the data you entered in EditTexts.

private void SalvarDados(String userId, String nome, String sobrenome, String idade) {
        String key = mDatabase.child("usuario").push().getKey();

        Post post = new Post(userId, nome, sobrenome, idade);
        Map<String, Object> postValues = post.toMap();

        Map<String, Object> childUpdates = new HashMap<>();
        childUpdates.put("/usuario-dados/" + userId + "/" + key, postValues);

    mDatabase.updateChildren(childUpdates);
}

To display them, just create an adapter in the main activity of your application.

    
26.09.2017 / 20:34