私がボタンを持っていると私は、そのようなのgetText、のsetTextなどのメソッドのいずれかを取得することができます...Androidは、getMethodを使用することにより、「setOnClickListener」方法に到達getMethods、getDeclaredMethod
Method mth = myButton.getClass().getMethod("getText", parameterTypes);
を使用しますが、私が取得しようとするとカント同じコードを使用する "setOnClickListener"メソッド Method mth = myButton.getClass().getMethod("setOnClickListener", parameterTypes);
例外が発生しました: "NoSuchMethodException" Exception。私が試してみました何
:
は空の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;
}
実際には見られない機能を送ります。 私はここにいくつかの誤解があることを明確に示しています。 は、このメソッドに到達する可能性がありますか? ありがとうございます。
このmyBtn.setOnClickListener(elemListener)を記述すると関数が機能するので、関数名は "setOnClickListener "setText"、 "getText"のように...私はなぜこの特定の関数には別の名前があるか、このようにアクセスできない場合、私のコードが動作しない理由を知りたい –