get String Resource from Context - Android App

Android examples for App:Resource

Description

get String Resource from Context

Demo Code


//package com.java2s;

import android.content.Context;

public class Main {
    public static String getStringResource(Context context, String name,
            String defaultValue) {
        String packageName = context.getPackageName();
        int resId = context.getResources().getIdentifier(name, "string",
                packageName);//from w  w w . j  ava2 s  .  co m
        if (resId != 0)
            return context.getResources().getString(resId);
        else
            return defaultValue;
    }
}

Related Tutorials