Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.Map;
import android.app.Activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Main {
    public static void mapToAndroidLayoutMapper(Class classObj, Map map, String prefixStr, View view) {

        for (Object keyObj : map.keySet().toArray()) {
            String keyStr = keyObj.toString();
            Field fieldObj = null;
            try {
                fieldObj = classObj.getField(prefixStr + "_" + keyStr);
            } catch (NoSuchFieldException e) {
                continue;
            }
            Object layoutObj = null;
            try {
                layoutObj = fieldObj.get(fieldObj);
            } catch (IllegalAccessException e) {
                continue;
            }
            Integer layoutIntvalue = (Integer) layoutObj;

            View selectedView = view.findViewById(layoutIntvalue);

            if (selectedView instanceof TextView) {
                TextView textView = (TextView) selectedView;
                textView.setText(String.valueOf(map.get(keyStr)));
            } else if (selectedView instanceof ImageView) {
                ImageView imageView = (ImageView) selectedView;

            }

        }

    }

    public static void mapToAndroidLayoutMapper(Class classObj, Map map, String prefixStr, Activity view) {

        if (map == null) {
            return;
        }

        for (Object keyObj : map.keySet().toArray()) {
            String keyStr = keyObj.toString();
            Field fieldObj = null;
            try {
                fieldObj = classObj.getField(prefixStr + "_" + keyStr);
            } catch (NoSuchFieldException e) {
                continue;
            }
            Object layoutObj = null;
            try {
                layoutObj = fieldObj.get(fieldObj);
            } catch (IllegalAccessException e) {
                continue;
            }
            Integer layoutIntvalue = (Integer) layoutObj;

            View selectedView = view.findViewById(layoutIntvalue);

            if (selectedView instanceof TextView) {
                TextView textView = (TextView) selectedView;
                textView.setText((String) map.get(keyStr));
            } else if (selectedView instanceof ImageView) {
                ImageView imageView = (ImageView) selectedView;

            }

        }

    }
}