Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.graphics.drawable.Drawable; import java.io.InputStream; public class Main { public static Drawable getAssetDrawable(Activity activity, String photoId) { try { String assetFile = "images/" + photoId + ".jpg"; InputStream stream = activity.getAssets().open(assetFile); return Drawable.createFromStream(stream, null); } catch (Exception error) { } return null; } public static Drawable getAssetDrawable(Activity activity, String photoId, int defaultImage) { Drawable drawable = getAssetDrawable(activity, photoId); if (drawable == null) { drawable = getDrawableFromResource(activity, defaultImage); } return drawable; } public static Drawable getDrawableFromResource(Activity activity, int id) { if (id > 0) { return activity.getResources().getDrawable(id); } return null; } }