Java 根据用户在android设置中的选择设置ImageView
我正在尝试制作一个应用程序,该应用程序将根据用户在我的应用程序设置中选择的ListPreference更改图像。有两幅画,一片森林和一片海洋。当选择Ocean时,发送到字符串的值是1,对于林,发送到字符串的值是2,但是当我运行此代码时,它会抛出一个错误,显示“Source not found”。有任何迹象吗Java 根据用户在android设置中的选择设置ImageView,java,android,android-imageview,Java,Android,Android Imageview,我正在尝试制作一个应用程序,该应用程序将根据用户在我的应用程序设置中选择的ListPreference更改图像。有两幅画,一片森林和一片海洋。当选择Ocean时,发送到字符串的值是1,对于林,发送到字符串的值是2,但是当我运行此代码时,它会抛出一个错误,显示“Source not found”。有任何迹象吗 public void showUserSettings() { String name; String pic; SharedPreferences sha
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);
}
}
}发布准确的错误。这就是错误。“未找到源”和用于设置源所在位置的按钮。