ボタンがあり、getText、setText などのメソッドを取得できます...
Method mth = myButton.getClass().getMethod("getText", parameterTypes);
しかし、同じコードを使用して「setOnClickListener」メソッドを取得しようとすると、
Method mth = myButton.getClass().getMethod("setOnClickListener", parameterTypes);
例外が発生します:「NoSuchMethodException」例外。
私が試したこと:
空のパラメータを送信
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;
}
関数が実際には見つかりません。ここで誤解があることは明らかです。この方法に到達することは不可能でしょうか?? 前もって感謝します。