get Resource Id - Android android.content

Android examples for android.content:Context

Description

get Resource Id

Demo Code

import android.content.Context;

public class Main {

  public static int getResourceId(Context context, String variableName, String resourceName) {

    try {//  w  ww. j a v a 2  s .  c o m
      return context.getResources().getIdentifier(variableName, resourceName, context.getPackageName());
    } catch (Exception e) {
      e.printStackTrace();
      return -1;
    }
  }

}

Related Tutorials