2011-06-06 22 views
0

嗨我有一個編輯首選項,我想更改代碼中存儲的值,這可能嗎?通過代碼更改editpreference中的文本

我試過,但沒有奏效

String input1 = hello; 
prefs.getString("location", "").replace(prefs.getString("location", ""), input1); 

回答

2
prefs.edit().putString("location", MODIFIED_STRING_HERE).commit(); 
+0

工作就像一個魅力,謝謝 – Amanni 2011-06-06 16:33:02

+0

很高興我能幫忙。 – 2011-06-06 16:39:56

0

你應該使用put *方法,然後將其提交到共享偏好。請參閱this example

要更新EDITTEXT內的文字,使用的setText方法,請參閱manpages