Android examples for java.lang.reflect:Method
Attempts to retrieve a public method in the given class from its name and parameter types.
import android.util.Log; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main{ private static final String TAG = ""; /**// w w w. j a v a 2 s . com * Attempts to retrieve a public method in the given class from its name and parameter types. * * @param methodName the name of the method * @param source the class where to search for the method * @param parameterTypes a list with the class type of parameters to expect * @return the method representation as a {@link Method} object, or {@code null} if the method was not found */ public static Method getMethodFromName(final String methodName, final Class<?> source, final Class<?>... parameterTypes) { try { return source.getDeclaredMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { Log.e(TAG, e.getMessage() + ""); } return null; } }