I have two EditText
and what I write I keep it in SharedPreferences
and I charge it in TextView
but I can only load the text of a EditText
and not both texts. What I want is to load the two texts in the same TextView
.
For example if I write in the first EditText
Hello, and in the second Qué tal in my TextView
it loads like this: Hello, What such .
My code is this:
public class MainActivity extends AppCompatActivity {
EditText uno, dos;
TextView receptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uno = (EditText) findViewById(R.id.uno);
dos = (EditText) findViewById(R.id.dos);
receptor = (TextView) findViewById(R.id.receptor);
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
// guardo los textos en sharedpreferences
uno.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
prefs.edit().putString("uno", s.toString()).commit();
}
});
dos.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
prefs.edit().putString("dos", s.toString()).commit();
}
});
// cargo los textos guardados en SharedPreferences
receptor.setText(prefs.getString("uno", "" + "dos"));
}
}
As you can see in my code I have tried with receptor.setText(prefs.getString("uno", "" + "dos"));
but in my TextView
I always receive what I wrote in uno
.
Is it possible to do what I ask? Thanks!