Hi I cant find the solutiıon for my question.
I take name of the images from db. And then I should give tat string to image.setImageResource. There are lots of answers which include getResources().getIdentifier(
But getResoruces() is not work. I get error like:
Error:(40, 21) error: cannot find symbol method getResources()
How can I solve this problem thanks.
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;
}
}
I use this code in a listview adapter class