get Resource String by name - Android App

Android examples for App:Resource

Description

get Resource String by name

Demo Code


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

public class Main {
    public static String getResourceString(String name, Context context) {
        int nameResourceID = context.getResources().getIdentifier(name,
                "string", context.getApplicationInfo().packageName);
        if (nameResourceID == 0) {
            return ""; //throw new IllegalArgumentException("No resource string found with name " + name);
        } else {//  w w w .  j  a v a2 s. c o m
            return context.getString(nameResourceID);
        }
    }
}

Related Tutorials