get ImageView Field Value via reflection - Android User Interface

Android examples for User Interface:ImageView

Description

get ImageView Field Value via reflection

Demo Code


//package com.java2s;
import java.lang.reflect.Field;

import android.util.Log;

import android.widget.ImageView;

public class Main {
     static int getImageViewFieldValue(Object object,
            String fieldName) {//from  www  . ja  v a  2s  . c  o m
        int value = 0;
        try {
            Field field = ImageView.class.getDeclaredField(fieldName);
            field.setAccessible(true);
            int fieldValue = (Integer) field.get(object);
            if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
                value = fieldValue;
            }
        } catch (Exception e) {
            Log.e("", e.getMessage());
        }
        return value;
    }
}

Related Tutorials