Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.view.View;

import java.lang.reflect.Method;

public class Main {

    private static void setOnClickListener(final Object object, final View view, final Method method) {
        if (null == view)
            return;
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Class<?>[] classes = method.getParameterTypes();
                    if (null == classes || 0 == classes.length) {
                        method.invoke(object);
                    } else {
                        method.invoke(object, view);
                    }
                } catch (Exception e) {
                    throw new RuntimeException(
                            "setOnClickListener fail,method is " + method.getName() + " \n" + e.getMessage());
                }
            }
        });
    }
}