我正在尝试制作一个应用程序,该应用程序将根据用户在我的应用程序设置中选择 ListPreference 来更改图像。有两张图片,一个森林和一个海洋。When Ocean is selected the value sent to the string is 1, and 2 for the forest, but when I run this code it throws an error saying "Source not found." 有什么建议吗?
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);
}
}
}