Skip to content
Advertisement

How to set ImageView in the AlterDialog Box

  • I am fetching the text and imageUrl from Firebase Realtime Database. I want to show the image and then display the text in the AlertDialogBox.
  • I am able to fetch the text and imageUrl. Able to set the text using setTitle() but when trying to display the image, not able to implement so.
  • Referred this but there in they are using drawable or static images.
  • Code
JavaScript
  • Or just the Text using below code
JavaScript
  • I have also created a CustomDialogBox view but not able to understand how should I pass the text and imageUrl value to that particular AlertDialogBox.
JavaScript

Advertisement

Answer

To, set the image you need to get ImageView id from CustomDialog XML file and then you can set particular image into ImageView.

So, first of all, get your custom view using getLayoutInflater().

Note: use one of the following as per your requirement.

JavaScript

Then, add view into builder.setView();

JavaScript

However, you also need to get ID of the all views which is located into your CustomDialog XML file.

JavaScript

Now, you can set your Image into ImageView Using Glide dependency.

JavaScript

Full example:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement