1

I want to set an image to the Uri if the Uri is empty, this is what I did:

if (imageUri == null)
{
    imageUri = imageUri.parse(String.valueOf(R.drawable.no_image_available));
}

It does not give any error but it doesn't work, is there any other way I can use to achieve this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Zack
  • 472
  • 7
  • 16

4 Answers4

1
Bitmap yourImageNotFoundBitmap = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.no_image_available);
if (imageUri == null){

yourImage.setImageBitmap(yourImageNotFoundBitmap);

}
1
Instead you can use glide library. If imageUrl is there then it will show otherwise it will take placeHolder image.


    Glide.with(context)
            .load(imageUrl)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .dontTransform()
            .placeholder(placeholder)
            .into(imageView);


http://www.gadgetsaint.com/android/circular-images-glide-library-android/#.WNiXPxKGNPN
Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36
0

Just check that Empty URI is not equal to followUri, this check includes check by null:

 if (!Uri.EMPTY.equals(followUri)) {
        //handle followUri
 }
0

This :

imageUri = imageUri.parse(String.valueOf(R.drawable.no_image_available));

will not give you a valid Uri.

There is Much more easier option:

option 1

 Uri uri = Uri.parse("android.resource://your.package.here/drawable/R.drawable.no_image_available"); 
imageview.setImageURI(uri);  //set the uri

OR use:

if (imageUri == null)
{
    imageView.setImageResource(R.drawable.no_image_available);
}
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62