Привет, я не могу найти solutiıon для моего вопроса. Я беру имя изображения из db. И тогда я должен дать tat string для image.setImageResource. Есть много ответов, которые включают getResources().getIdentifier(
Но getResoruces() не работает. Я получаю ошибку: Ошибка: (40, 21) ошибка: не удается найти метод символов getResources() Как я могу решить эту проблему.Получение идентификатора для имени
public class ReceivedItemAdapter extends ArrayAdapter<ReceivedItem> {
public ReceivedItemAdapter(Context context, ArrayList<ReceivedItem> items){
super(context,R.layout.row_item_received,items);
}
public View getView(int position, View convertView, ViewGroup parent) {
View customView = LayoutInflater.from(this.getContext())
.inflate(R.layout.row_item_received, parent, false);
ReceivedItem item = getItem(position);
TextView textName = (TextView) customView.findViewById(R.id.nameTextView);
TextView textCalorie = (TextView) customView.findViewById(R.id.calorieTextView);
ImageView imageView = (ImageView) customView.findViewById(R.id.imageView);
textName.setText(item.getName());
textCalorie.setText(item.getCalorie()+ " cal");
String mDrawableName = item.getImageName();
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
imageView.setImageResource(resID);
customView.setTag(item.getId());
return customView;
}
}
Я использую этот код в ListView адаптер класса
пожалуйста наклеить, как и где вы звоните GetResources() –
' getResources() 'работает. но вам нужен «контекст», чтобы получить доступ к этому методу –
Как добавить контекст? – berkt