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.
View view = getLayoutInflater().inflate(R.layout.CustomDialog, null); // for activity
View view = ((ViewHolder) holder).mainActivity.getLayoutInflater().inflate(R.layout.CustomDialog, null); // for adapter class
View view = getActivity().getLayoutInflater().inflate(R.layout.CustomDialog, null); // for fragment
Then, add view
into builder.setView();
builder.setView(view);
However, you also need to get ID of the all views which is located into your CustomDialog XML file.
TextView textview = view.findViewById(R.id.eTextView);
ImageView imageview = view.findViewById(R.id.eImageView);
Now, you can set your Image into ImageView Using Glide dependency.
Glide.with(context).load(url).into(imageview);
Full example:
View view = getLayoutInflater().inflate(R.layout.CustomDialog, null);
ImageView imageview = view.findViewById(R.id.eImageView);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Explanation");
builder.setView(view);
builder.setMessage(list.get(position).getExplaination());
url = list.get(position).getImageUrl();
Glide.with(context).load(url).into(imageview);
Log.i("URL", url);
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// dismiss dialog
dialogInterface.dismiss();
}
});
builder.show();