gpt4 book ai didi

android - 如何将 registerOnSharedPreferenceChangeListener 添加到 ListActivity?

转载 作者:行者123 更新时间:2023-11-29 00:50:21 24 4
gpt4 key购买 nike

当我调用 Intent 时

public class TInfo extends ListActivity 
implements OnSharedPreferenceChangeListener{

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
initvars();
setListAdapter(new TAdapter()); // class TAdapter extends ArrayAdapter<String>
}

在哪里以及如何调用 registerOnSharedPreferenceChangeListener

最佳答案

在您的情况下,它将是这样的:

public class TInfo extends ListActivity 
implements OnSharedPreferenceChangeListener{

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
initvars();
setListAdapter(new TAdapter()); // class TAdapter extends ArrayAdapter<String>
}

@Override
public void onSharedPreferenceChanged (SharedPreferences sharedPreferences, String key){
// do whatever you want here
}
}

onSharedPreferenceChanged is called when a shared preference is changed, added, or removed. This may be called even if a preference is set to its existing value.

关于android - 如何将 registerOnSharedPreferenceChangeListener 添加到 ListActivity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3274054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com