I have Button and I can get any of its methods such as getText,setText ... using
Method mth = myButton.getClass().getMethod("getText", parameterTypes);
but when I try to get "setOnClickListener" method using the same code
Method mth = myButton.getClass().getMethod("setOnClickListener", parameterTypes);
I am getting Exception : "NoSuchMethodException" Exception.
What I have tried:
send empty params
Class<?>[] parameterTypes = new Class[] {};
`Method mth = myButton.getClass().getMethod("setOnClickListener", parameterTypes);` NOT working the same Exception: "NoSuchMethodException"
i tried to get all the methods and identify it by name.
Method[] arrMethods = objElem.getClass().getMethods();
Method listener = getMethodByName(arrMethods,"setOnClickListener");
public Method getMethodByName(Method[] arrMethods,String MethodName)
{
for(int i=0;i<arrMethods.length;i++)
{
if(arrMethods[i].getName() == MethodName)
{
return arrMethods[i];
}
}
return null;
}
the function actually not found . its clearly that I have some misunderstanding here . may be its not posible to reach this method?? Thanks in advance.