Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

public class Main {
    public static String getStringByName(Context context, String name) {
        int resid = context.getResources().getIdentifier(name, "string", context.getPackageName());

        if (resid == 0)
            return null;

        return context.getString(resid);
    }

    public static String getStringByName(Context context, String name, int subid) {
        int resid;

        if (subid < 0) {
            resid = context.getResources().getIdentifier(String.format("%s_n%d", name, -subid), "string",
                    context.getPackageName());
        } else {
            resid = context.getResources().getIdentifier(String.format("%s_p%d", name, subid), "string",
                    context.getPackageName());
        }

        if (resid == 0)
            return null;

        return context.getString(resid);
    }
}