get Image Resource Id - Android App

Android examples for App:Resource

Description

get Image Resource Id

Demo Code


//package com.java2s;
import android.content.Context;

public class Main {
    /**/*  w ww.  j a v  a2s.  c o m*/
     * @param context
     * @param name
     * @return
     */
    public static int getImageResourceId(Context context, String name) {
        try {
            return context.getResources().getIdentifier(name, "drawable",
                    context.getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}

Related Tutorials