get Id Values by Class from R - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

get Id Values by Class from R

Demo Code


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

import java.util.HashMap;

public class Main {
    private static HashMap<Integer, String> mIdValues;

    private static void getIdValues(Class R) {
        mIdValues = new HashMap<Integer, String>();
        for (Field f : R.getFields()) {
            try {
                mIdValues.put(//  www .  j a  v  a2  s.c  o  m
                        (Integer) R.getField(f.getName())
                                .get(Integer.class), f.getName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials