Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;

import android.view.View;

public class Main {
    public static String getIDName(View view, Class<?> clazz) {

        try {
            Integer id = view.getId();
            Field[] ids = clazz.getFields();
            for (int i = 0; i < ids.length; i++) {
                Object val = ids[i].get(null);
                if (val != null && val instanceof Integer && ((Integer) val).intValue() == id.intValue()) {
                    return ids[i].getName();
                }
            }
        } catch (Exception e) {
        }
        return "";
    }
}