Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide - How load image before dialog show?

I'm working with Glide for server loading images. I need to load image before some dialog shows.

What is the best approach?

EDIT: This is an example from my code:


    On my dialog class

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        setContentView(R.layout.dialog_alert);
        ButterKnife.bind(this);

        int size = mActivity.getResources().getDimensionPixelSize(R.dimen.product_icon);
        String productThumbnailUrl = api.getThumbnailUrl(mProduct.getImage(), size, size);

        Glide.with(mActivity)
        .load(productThumbnailUrl)
        .placeholder(R.drawable.icon_default)
        .into(mImage);
    }

    On my activity:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        [...]

        AlertProduct dialog = new AlertProduct(this, product);
        dialog.show();
    }


like image 621
SilentHill Avatar asked Jan 26 '26 10:01

SilentHill


1 Answers

Loading into targets should do what you want.

If you simply want to load a Bitmap so that you can interact with it in some special way other than displaying it directly to the user, maybe to show in a notification, or upload as a profile photo, Glide has you covered.

SimpleTarget provides reasonable default implementations for the much larger Target interface and let's you focus on handling the result of your load.

like image 133
fweigl Avatar answered Jan 28 '26 00:01

fweigl