Skip to content

How to programmatically set image to ImageView

Margarita Ostrovskaia edited this page May 5, 2020 · 2 revisions
  • get name of image
  • create Drawable object
  • set this object in view
        // set Artist image
        String name = artist.getTitle().replaceAll(" ", "_").toLowerCase();
        Drawable drawable = context.getDrawable(context.getResources().getIdentifier(name,
                context.getString(R.string.def_type),
                context.getPackageName()));
        holder.imageView.setImageDrawable(drawable);

Clone this wiki locally