According to that answer in the SOEN, what you want is not possible - the string.xml
in fact it is read-only. The recommended alternative is to use SharedPreferences
: a way to create and persist user preferences data.
At this link has an example of how to use them (if this alternative really suits you, of course):
public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Recupera as preferências salvas
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@Override
protected void onStop(){
super.onStop();
// Atribui uma nova preferência; isso é feito através de um Editor
// Todos os objetos são de android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Confirma as edições
editor.commit();
}
}
Thank you. I’m going to study this Sharedpreferences , I think this is really.
– Zeca
@Zeca You can accept this answer as the correct one, making it clear to everyone that it has solved the problem and giving reputation to you and the author of the answer.
– Maniero