开发者

Android getWindow to set the background of my activity according to Listpreference

I've basically created a ListPreference where user would be able to choose from a list of options. After they have chosen one of the available option,the app will return to the main activity and the background image will change accordingly,however,it seems my app would't be able to detect the change in preference and change the background image.Can somebody please advice?Thanks!***Below snippet shows after my main activity resume,how it detects the change in preference and change the background image.

protected void onResume() 
{
    super.onResume();
    listener = new SharedPreferences.OnSharedPreferenceChangeListener() {
          public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
              if(key.equals("listPrefwall")){
                tv.setText(prefs.getString("listPrefwall", "ondon"));   


                    if(prefs.getString("listPrefwall", "ondon")=="ondon")
                    {
                        getWindow().setBackgroundDrawableResource(R.drawable.ondon);
                        tv.setText("testing");
                    }
                     else if(prefs.getString("li开发者_运维技巧stPrefwall", "ondon")=="japan")
                     {
                         getWindow().setBackgroundDrawableResource(R.drawable.japan);
                         tv.setText("pivot");
                      }
        }
          }
        };
    settings.registerOnSharedPreferenceChangeListener((OnSharedPreferenceChangeListener) listener);

}


Maybe your "settings" member retains a cached value? Try using the "prefs" object that gets passed to your listener.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜