它获取带有 setText 的 Text .. 但我想稍后再次重置该值。
我可以在网上找到的结果给了我使用 setText("") 的答案,但这并没有真正重置文本 IT 只会清空文本。
所以我看不到在我的 xml 中声明的默认文本......所以你有什么想法吗?
小智 0
这就是我要做的:
将默认值保存在 SharedPreferences 中,如下所示:
public void saveUsername(String username) {
SharedPreferences sp = context.getSharedPreferences(
Constants.SP_APP_PREFS, Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putString(Constants.SP_IM_USERNAME, username);
editor.commit();
}
public String getUsername() {
SharedPreferences sp = context.getSharedPreferences(
Constants.SP_APP_PREFS, Context.MODE_PRIVATE);
String username = sp.getString(Constants.SP_IM_USERNAME, "");
return username;
}
public void resetTextView(TextView view){
view.setText(getUsername());
}
Run Code Online (Sandbox Code Playgroud)
您可以随时检索默认值。
| 归档时间: |
|
| 查看次数: |
6643 次 |
| 最近记录: |