我正在尝试根据应用程序设置中用户对ListPreference的选择来创建一个可以更改图像的应用程序。有两张照片,一片森林和一片海洋。选择Ocean时,发送到字符串的值为1,林为2,但是当我运行此代码时,会抛出错误消息“找不到源”。任何siggestions?
public void showUserSettings() {
String name;
String pic;
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
name = sharedPrefs.getString("your_name", "NULL");
pic = sharedPrefs.getString("pic_what", "for");
int whatPic = Integer.parseInt(pic);
TextView tvName = (TextView) findViewById(R.id.tvName);
tvName.setText(name);
if(whatPic==1) {
ImageView img = (ImageView) findViewById(R.id.iView);
img.setImageResource(R.drawable.ocean);
}else if(whatPic==2); {
ImageView img = (ImageView) findViewById(R.id.iView);
img.setImageResource(R.drawable.forest);
}
}
}