There is a custom listview which displays image and text. I am using Glide image library to load the image. So when i search the image and text displays in listview but before image loads if i click on it Java Null Pointer exception is seen. How to avoid making click before image loads or any change is required to done on the itemclick listener.
ItemClick:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
descusers du = dusers.get(position);
final String Limage = du.image;
if (!Limage.isEmpty()) {
final ImageView imageView1 = (ImageView) view.findViewById(R.id.imageList);
final GlideBitmapDrawable bitmapDrawable = (GlideBitmapDrawable) imageView1.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
Dialog builder = new Dialog(this);
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//nothing;
}
});
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(yourBitmap);
p=new PhotoViewAttacher(imageView);
builder.addContentView(imageView, new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
builder.show();
}
}
I am checking if there is image url then fetch the image after loading using Glide, but exception when i click before image loads. any suggestion?
Answer:
Created Onclicklistener in Adapter passing display activity.
viewholder.iview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog builder = new Dialog(listdisplay);
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//nothing;
}
});
ImageView imageView = new ImageView(listdisplay);
final GlideBitmapDrawable bitmapDrawable = (GlideBitmapDrawable) finalViewholder.iview.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
imageView.setImageBitmap(yourBitmap);
p=new PhotoViewAttacher(imageView);
builder.addContentView(imageView, new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
builder.show();
}
});
Adapter constructor:
private Activity listdisplay;
public DescAdapter(listdisplay ds, ArrayList<descusers> dusers,Activity listdisplay) {
this.ds = ds;
this.dusers = dusers;
this.listdisplay = listdisplay;
}