get Xml Id from resource - Android App

Android examples for App:Resource

Description

get Xml Id from resource

Demo Code


import java.lang.reflect.Field;
import android.content.Context;
import android.util.Log;

public class Main{
    public static int getXmlId(Context ctx, String resName) {
        Integer id = ctx.getResources().getIdentifier(resName, "xml",
                ctx.getPackageName());//from w w  w . java2 s. c  o  m
        return id;
    }
    private static String getPackageName() {
        return ctx.getPackageName();
        //return "com.lostad.app";
    }
}

Related Tutorials