get Layout Id from res - Android App

Android examples for App:Resource

Description

get Layout Id from res

Demo Code


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

public class Main{
    public static int getLayoutId(Context ctx, String layoutName) {
        Integer id = ctx.getResources().getIdentifier(layoutName, "layout",
                ctx.getPackageName());/*from   w ww . j a  va 2s  .  c o  m*/
        return id;
    }
    private static String getPackageName() {
        return ctx.getPackageName();
        //return "com.lostad.app";
    }
}

Related Tutorials