Getting icon from url and icon from drawable it is taking only from drawable
You need to pass your arrayList.get(position).getIcon()
instead of "icon"
in context.getResources().getIdentifier()
Also read how getIdentifier()
works
Return a resource identifier for the given resource name. A fully qualified resource name is of the form "package:type/entry".
Returns
: int The associated resource identifier. Returns 0 if no such resource was found. (0 is not a valid resource ID.)
Try this way
int resID = context.getResources().getIdentifier(String.valueOf(arrayList.get(position).getIcon()), "drawable",context.getPackageName()); "drawable",context.getPackageName());
// if resID == 0 means the icon is not available in drawable folder
// so it will load icon from url using Glide
if (resID == 0) {
Log.d("TAG", "onBindViewHolder: Glide" + resID);
Glide.with(context)
.load(imageUrl)
.apply(requestOptions
.placeholder(R.drawable.default_favicon)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fitCenter())
.into(viewHolder.tvIcon);
}
// if resID != 0 means the icon is available in drawable folder
// so it will load icon from drawable folder
else {
Log.d("TAG", "onBindViewHolder: " + resID);
viewHolder.tvIcon.setImageResource(resID);
}