Hunt
Hunt

Reputation: 8435

Set Resource drawable to BitmapDrawable

I have derived a class BitmapDrawable in android for some reason but I want to know how can I assign a resource id ( I mean the icon in a drawable folder ) to My class ?

as its super constructor as for a Resources object ( but my class doesnt have access to getResources() ) so how can I set the Resource id to BitmapDrawable.

But i think getting getResources won't help me as BitmapDrawable doesn't have (Resources res , int id) constructor

static class DownloadedDrawable extends BitmapDrawable {
        private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

        public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask) {

            bitmapDownloaderTaskReference =
                new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask);
        }

        public BitmapDownloaderTask getBitmapDownloaderTask() {
            return bitmapDownloaderTaskReference.get();
        }
    }

Upvotes: 0

Views: 1407

Answers (1)

ByteMe
ByteMe

Reputation: 1476

You could set the image from an activity when you create your bitmap. Alternatively you can use

getContext().getResources() 

to get the resources from an class

Upvotes: 2

Related Questions