get Value from AbsListView by name via reflection - Android User Interface

Android examples for User Interface:ListView

Description

get Value from AbsListView by name via reflection

Demo Code


//package com.java2s;
import android.widget.AbsListView;
import java.lang.reflect.Field;

public class Main {
    public static <T> T getValue(AbsListView view, String name) {

        final Field field;
        try {/*ww  w  .jav  a  2  s  . c o m*/
            field = AbsListView.class.getDeclaredField(name);
            field.setAccessible(true);
            return (T) field.get(view);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related Tutorials