Retrieves the resource ID from a string (for example, a drawable from the image name). - Android Graphics

Android examples for Graphics:Drawable Operation

Description

Retrieves the resource ID from a string (for example, a drawable from the image name).

Demo Code


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

public class Main {
    /**//  w ww .  ja  va2 s  . c o  m
     * Retrieves the resource ID from a string (for example, a drawable from the
     * image name).
     *
     * @param context Application or Activity context
     * @param type Resource type
     * @param resourceName Resource's name
     *
     * @return Resource ID of the named resource
     */
    public static int resourceIdFromString(final Context context,
            final String type, final String resourceName) {
        return context.getResources().getIdentifier(resourceName, type,
                context.getPackageName());
    }
}

Related Tutorials