Android examples for java.lang.reflect:Field Value
set Field Value via reflection
import java.lang.reflect.Field; import java.lang.reflect.Method; import android.util.Log; public class Main{ private static final String TAG = ""; public static void setFieldValue(Class<?> fieldClass, String fieldName, Object instance, Object value) { try {// w w w .ja v a 2s. co m final Field field = fieldClass.getDeclaredField(fieldName); field.setAccessible(true); field.set(instance, value); } catch (Exception e) { Log.w(TAG, Log.getStackTraceString(e)); } } }