Code example for ImageView

Methods: getResourcessetImageDrawable

0
        // If we don't have a new Drawable, something went wrong... bail out. 
        if (newDrawable == null) return previousBitmap();
 
        if (mPreviousDrawable == null || mDurationInMillis == 0) {
            // Set the new one immediately. 
            mTarget.setImageDrawable(newDrawable);
        } else { 
            // Set up a transition from the previous Drawable to the new one. 
            final Drawable[] beforeAndAfter = new Drawable[2];
            beforeAndAfter[0] = mPreviousDrawable;
            beforeAndAfter[1] = newDrawable;
            final TransitionDrawable transition = new TransitionDrawable(beforeAndAfter);
            mTarget.setImageDrawable(transition);
            transition.startTransition(mDurationInMillis);
        } 
 
        // Remember this for next time, so that we can transition from it to the 
        // new one. 
        mPreviousDrawable = newDrawable;
 
        return previousBitmap(); 
    } 
 
    private Bitmap previousBitmap() {
        return (mPreviousDrawable == null)
                ? null 
                : ((BitmapDrawable) mPreviousDrawable).getBitmap();
    } 
 
    /** 
     * Obtain the default drawable for a contact when no photo is available. 
     */ 
    private Drawable defaultDrawable() {
        Resources resources = mTarget.getResources();
        final int resId = ContactPhotoManager.getDefaultAvatarResId(true, false);
        try { 
            return resources.getDrawable(resId);
        } catch (NotFoundException e) {
            Log.wtf(TAG, "Cannot load default avatar resource.");
            return null; 
        } 
    } 
 
    private BitmapDrawable decodedBitmapDrawable(byte[] compressed) {
        Resources rsrc = mTarget.getResources();
        Bitmap bitmap = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
        return new BitmapDrawable(rsrc, bitmap);
    } 
 
} 
Connect your IDE to all the code out there  Get Codota for Java