I want to get the email that the person entered in the login to display it in a textview, how do I do it? obs, This text edit is already being used to login
I want to get the email that the person entered in the login to display it in a textview, how do I do it? obs, This text edit is already being used to login
I imagine you want to open another activity and display in a TextView, the typed email on the login screen.
If it is only for display and use as proof of concept, you can do it as follows:
LoginActivity.class
String txt = editText.getText().toString();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra("login", txt);
startActivity(intent);
MainActivity.class
TextView txtEmail = (TextView) findViewById(R.id.tvEmail);
Bundle b = getIntent().getExtras();
if(b!=null){
String email = b.getString("login");
txtEmail.setText(email);
}
But I advise you to create a local base, so that you do not have a problem on display, if you continue with a navigation on other screens and have to return to MainActivity, for example.
I hope I have helped.
A simple way to persist data is to use SharedPreference
as shown in the documentation on How to save key-value sets . See below for an example of how to save, assuming you have a EditText
variable named name myEditText
:
SharedPreferences sharedpreferences = getSharedPreferences("pref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("str_email", myEditText.getText().toString());
editor.commit();
To redeem:
SharedPreferences pref = getSharedPreferences("pref", MODE_PRIVATE);
String email = pref.getString("str_email", null);
myEditText.setText(email);
See Save Value on SharedPreference for more details.
In this way, at any time of your application, you can regroup the value that was saved in a given key. See here at Persistence levels of data in Android applications other approaches.