user2269164 user2269164 - 2 months ago 5x
Android Question

how to use OnItemClick listener when Glide/Picasso image library is used

I have a custom listview with image and text and it is loaded properly in listview by using the Glide image library. Now i want to implement an OnItemClickListener on imageview to show the image in another activity.

Adapter code:

public class DescAdapter extends BaseAdapter {

private final listdisplay ds;
private ArrayList<descusers> dusers;
private ArrayList<descusers> orig;

public DescAdapter(listdisplay ds, ArrayList<descusers> dusers) {
this.ds = ds;
this.dusers = dusers;

public int getCount() {
return dusers.size();

public Object getItem(int position) {
return dusers.get(position);

public long getItemId(int position) {
return position;

public View getView(int position, View convertView, ViewGroup parent) {

descusers du = dusers.get(position);
String username = du.loginname;
String descCrip=du.descCrip;
String Limage = du.image;
long Ptime = du.Ptime;

Viewholder viewholder = null;

if(convertView==null) {
viewholder = new Viewholder();
convertView = LayoutInflater.from(ds).inflate(R.layout.customlist, null);
viewholder.uname = (TextView) convertView.findViewById(;
viewholder.desc = (TextView) convertView.findViewById(;
viewholder.time = (TextView)convertView.findViewById(;

viewholder.iview = (ImageView) convertView.findViewById(;

}else {

viewholder = (Viewholder) convertView.getTag();


if (Limage.trim().isEmpty()) {
} else {


return convertView;

OnItemClick code:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

final ImageView imageView = (ImageView) view.findViewById(;
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
Intent intent = new Intent(this, cust.class);
intent.putExtra("BitmapImage", yourBitmap);


Receiveing intent:

Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
imagedisplay = (ImageView)findViewById(;

But when i click on the image below exception is seen.

java.lang.ClassCastException: com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable cannot be cast to

 final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();

Change this BitmapDrawable casting to GlideBitmapDrawable.

final GlideBitmapDrawable bitmapDrawable = (GlideBitmapDrawable ) imageView.getDrawable();

I hope Picaso giving the drawable as GlideBitmapDrawable format.