Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Created August 3, 2016 14:08
Show Gist options
  • Save vincent1086/28c997eda7a2de70fdd34be75f5c4d43 to your computer and use it in GitHub Desktop.
Save vincent1086/28c997eda7a2de70fdd34be75f5c4d43 to your computer and use it in GitHub Desktop.
Android - get class inner variable
//////////////////////////////////////////////////////////
//// @usage getClassField("mPageMargin", ViewPager.class)
//////////////////////////////////////////////////////////
public int getClassField(String fieldName, Class<?> clz) {
try {
Field thisField = clz.getDeclaredField(fieldName);
return thisField.getInt(thisField);
} catch (Exception e) {
throw new RuntimeException("Not found field " + fieldName + ", Error : " + e.getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment