我在MapsActivity中写了sharedPreference,它接受一个答案,如果答案正确,回收视图中的图像将会改变,但是onBindViewHolder中的getSharedPreference是红色的,而且,我试图得到
Resources res = getResources();
Drawable newimages = res.getDrawable(R.drawable.TH_logo_solo_ok);
该getResources();
也是红色的,这在里面适用吗?onBindViewHolder
?或者我的方法是错的。
这只是代码的一部分。MapsActivity
.setPositiveButton("Ketemu!",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
SharedPreferences preferences = getSharedPreferences("idTreasure", MODE_PRIVATE);
hasil.setText(userInput.getText());
if(hasil.getText().toString().equals("harmonia")){
SharedPreferences.Editor editor = preferences.edit();
String idGambar = hasil.getText().toString();
editor.putString("idGambar",idGambar);
editor.apply();
selamat();
}else{
salah();
}
}
})
这是我的onBindViewHolder
在我的适配器上
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
Information current = data.get(position);
// holder.title.setText(current.title);
holder.iconth.setImageResource(current.iconth);
holder.subtitle.setText(current.subtitle);
}
基本上,我想在下面的代码中实现所有这些代码onBindViewHolder
因为那是我唯一知道的改变回收视图中图像的地方,
SharedPreferences preferences = getSharedPreferences("idTreasure", MODE_PRIVATE);
String ImagePrefs = preferences.getString("idGambar", "Key not correct");
tim = (TextView) findViewById(R.id.tim);
tim.setText(ImagePrefs);
if(ImagePrefs.getText().toString().equals("harmonia")){
Resources res = getResources();
Drawable newimages = res.getDrawable(R.drawable.TH_logo_solo_ok);
holder.iconth.setImageResource(current.newimages);
}
我该怎么做,或者用另一种方式?
相似问题