Search code examples
androidandroid-fragmentsandroid-popupwindow

How to setimage for an Imageview in a popup dialog


This is my Popup class,

public class Popup {

    public void showDialog(Activity activity, String url){
        final Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.popup_playerstats);

        ImageView imageFirst= (ImageView) dialog.findViewById(R.id.img_First);

        ImageView dialogButton = (ImageView) dialog.findViewById(R.id.close);
        dialogButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        dialog.show();

    }
}

And my onClick method of Fragment is,

public void onClick(final View v) {
    Popup alert = new Popup();
    switch (v.getId()) {
        case R.id.button_1:
            alert.showDialog(getActivity(),url);
            break;
        case R.id.button_2:
            alert.showDialog(getActivity(),url1);
            break;
        default:
            // some code here
            break;
    }
 }

I need to use the String variable url or url1 and setimage on ImageView imageFirst.

Help how could I do this?


Solution

  • First add the Glide dependency to your build.gradle Section.

    dependencies {
        // glide
        compile 'com.github.bumptech.glide:glide:3.7.0'
    }
    

    Then

    ImageView imageFirst= (ImageView) dialog.findViewById(R.id.img_First);
    Glide.with(activity).load(url)
                    .thumbnail(0.5f)
                    .crossFade()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(imageFirst);