Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {

    public static int getDrawableResource(Context ctx, String name) {
        String packageName = ctx.getPackageName();
        try {
            Object obj;
            obj = Class.forName(packageName + ".R$drawable").newInstance();
            return Class.forName(packageName + ".R$drawable").getDeclaredField(name).getInt(obj);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}