如何将文本保存为文本编辑,以便在离开活动并重新输入后,它会出现在相同的编辑文本中?
switchbutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Switch sw = (Switch) v;
if (sw.isChecked()) {
SharedPreferences settings = getPreferences(0);
SharedPreferences.Editor editor1 = settings.edit();
editor1.putString("nombre", ed1.getText().toString());
SharedPreferences.Editor editor2 = settings.edit();
editor2.putString("apellido", ed2.getText().toString());
SharedPreferences.Editor editor3 = settings.edit();
editor3.putString("ciudad", ed3.getText().toString());
SharedPreferences.Editor editor4 = settings.edit();
editor4.putString("calle", ed4.getText().toString());
SharedPreferences.Editor editor5 = settings.edit();
editor5.putString("numero", ed5.getText().toString());
editor1.commit();
editor2.commit();
editor3.commit();
editor4.commit();
editor5.commit();
} else {
Toast.makeText(OtraActivity.this, "Datos no guardados",
Toast.LENGTH_LONG).show();
}
}});