我正在编写一个保存您的首选项的小应用程序。在主要 Activity 中,应显示这些首选项。但是,当从 PreferenceActivity 类返回时,我仍然得到旧值。只有在我通过“后退”按钮实际退出应用程序后, View 才会更新。
我试过将 setText 命令放在 onResume() 和 onRestoreInstanceState() 函数中,但实际上没有刷新它。
我需要做什么才能让它刷新?
最佳答案
您应该覆盖 onSharedPreferenceChanged 以对更改的偏好作出 react :
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
//code
}
关于android - 从 Activity 返回时刷新 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301719/