Gets the resource id from the name and type ex... - Android App

Android examples for App:Resource

Description

Gets the resource id from the name and type ex...

Demo Code


//package com.java2s;

import android.content.Context;

import android.support.annotation.NonNull;

public class Main {
    /**//from  w w  w.  j av a  2  s.  com
     * Gets the resource id from the name and type
     * ex... getResIdFromIdentifier(ctx, "error_msg", "string");
     * @param context
     * @param name
     * @param defType
     * @return resourceId
     */
    public static int getResIdFromIdentifier(@NonNull Context context,
            String name, String defType) {
        return context.getResources().getIdentifier(name, defType,
                context.getPackageName());
    }
}

Related Tutorials