Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumoshu/508091 to your computer and use it in GitHub Desktop.
Save mumoshu/508091 to your computer and use it in GitHub Desktop.
private String getAttributeValueThenInjectResources(AttributeSet attrs,
String name) {
String value = attrs.getAttributeValue(null, name);
if (value == null)
return "";
String[] tokens = value.split("/");
if (tokens.length == 2 && tokens[0].equals("@string")) {
Field field;
try {
field = R.string.class.getField(tokens[1]);
return context.getString(field.getInt(null));
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
}
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment