Hello
I have a question about a process that I can not do. I have the following screen, and I wanted the EditText user to already be populated with the user name or the user's email. I'm new to the mobile programming area, and I tried to do this with sharedpreferences, but I could not mount the code.
Follow the activity screen and firebase database that I'm using. FollowthecodeImadefromactivityhere.publicclassMessageActivityextendsAppCompatActivity{
EditTextedtNome,edtMensagem;ButtonbtnEnviarMensagem;Mensagemmensagem;FirebaseDatabasefirebaseDatabase;DatabaseReferencedatabaseReference;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_mensagem);edtNome=(EditText)findViewById(R.id.edtUsuario);edtMensagem=(EditText)findViewById(R.id.edtMensagem);btnEnviarMensagem=(Button)findViewById(R.id.btnEnviarMensagem);databaseReference=FirebaseDatabase.getInstance().getReference();btnEnviarMensagem.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){mensagem=newMensagem();mensagem.setNome(edtNome.getText().toString());mensagem.setMensagem(edtMensagem.getText().toString());DatabaseReferencedatabaseReference=FirebaseDatabase.getInstance().getReference();databaseReference.child("mensagens").push().setValue(firebaseDatabase, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
//Problem with saving the data
if (databaseError != null) {
Toast.makeText(MensagemActivity.this, "Erro ao criar ocorrência / erro ao inserir dados!", Toast.LENGTH_LONG).show();
} else {
//Data uploaded successfully on the server
databaseReference.child("nome").setValue(edtNome.getText().toString());
databaseReference.child("texto").setValue(edtMensagem.getText().toString());
Toast.makeText(MensagemActivity.this, "Mensagem enviada com sucesso!", Toast.LENGTH_LONG).show();
retornaTela();
}
}
});
}
});
}