Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import java.lang.reflect.Field; import java.util.ArrayList; public class Main { /** * A helper method to get a String[] out of a fieldArray * * @param fields R.strings.class.getFields() * @return a String[] with the string ids we need */ private static String[] getDefinedFonts(Context ctx, Field[] fields) { ArrayList<String> fieldArray = new ArrayList<String>(); for (Field field : fields) { if (field.getName().contains("define_font_")) { fieldArray.add(getStringResourceByName(ctx, field.getName())); } } return fieldArray.toArray(new String[fieldArray.size()]); } /** * helper class to retrieve a string by it's resource name * * @param ctx * @param resourceName * @return */ private static String getStringResourceByName(Context ctx, String resourceName) { String packageName = ctx.getPackageName(); int resId = ctx.getResources().getIdentifier(resourceName, "string", packageName); if (resId == 0) { return ""; } else { return ctx.getString(resId); } } }