I want to write a component. I can use the annotation method to automatically find this view and find the method for clicking events, like this (the annotation class will not be posted ):
@ Viewclick (viewid = R. Id. clickbtn, clickmethod = "btnclickmethod ")
Private button btnclick;
However, some problems are encountered in the process. The log is as follows:
12-27 19:04:51. 090: W/system. err (14345): Java. lang. illegalargumentexception: Expected extends er of Type COM. mobile. component. setting. syssettingactivity, but got Java. lang. class <COM. mobile. component. setting. syssettingactivity>
12-27 19:04:51. 100: W/system. Err (14345): At java. Lang. Reflect. method. invokenative (native method)
12-27 19:04:51. 100: W/system. Err (14345): At java. Lang. Reflect. method. Invoke (method. Java: 511)
12-27 19:04:51. 100: W/system. Err (14345): At com. Mobile. component. Base. baseactivity $1. onclick (baseactivity. Java: 80)
12-27 19:04:51. 100: W/system. Err (14345): at Android. View. View. Adjust mclick (view. Java: 3538)
12-27 19:04:51. 100: W/system. Err (14345): at Android. View. View $ invoke mclick. Run (view. Java: 14319)
12-27 19:04:51. 100: W/system. Err (14345): at Android. OS. handler. handlecallback (handler. Java: 608)
12-27 19:04:51. 100: W/system. Err (14345): at Android. OS. handler. dispatchmessage (handler. Java: 92)
12-27 19:04:51. 100: W/system. Err (14345): at Android. OS. low.loop (low.java: 156)
12-27 19:04:51. 100: W/system. Err (14345): at Android. App. activitythread. Main (activitythread. Java: 5045)
12-27 19:04:51. 100: W/system. Err (14345): At java. Lang. Reflect. method. invokenative (native method)
12-27 19:04:51. 100: W/system. Err (14345): At java. Lang. Reflect. method. Invoke (method. Java: 511)
12-27 19:04:51. 100: W/system. Err (14345): At com. Android. Internal. OS. zygoteinit $ methodandargscaller. Run (zygoteinit. Java: 784)
12-27 19:04:51. 100: W/system. Err (14345): At com. Android. Internal. OS. zygoteinit. Main (zygoteinit. Java: 551)
12-27 19:04:51. 100: W/system. Err (14345): At Dalvik. system. nativestart. Main (native method)
Analysis: I set the Click Event and view in a class method. setonclicklistener (), so COM. mobile. component. base. baseactivity $1. onclick (baseactivity. java: 80) This line of log, baseactivity $1. onclick indicates an anonymous internal class, such as onclick;
Call this in The onclick method. getclass () is not the current class, but an anonymous internal class, similar to baseactivity $1. onclick, so I always prompt that I cannot find the method of my class, so I will do this: baseactivity. this. getclass (). After the transformation, the current class is obtained.
View. setonclicklistener (New onclicklistener (){
@ Override
Public void onclick (view v ){
Method method;
Log. I ("tag", "baseactivity. this = "+ baseactivity. this + "\ n" + "baseactivity. this. getclass () = "+ baseactivity. this. getclass ());
Method = baseactivity. This. getclass (). getdeclaredmethod (clickmethod, view. Class );
If (method! = NULL ){
Method. Invoke (baseactivity. This, V );
} Else {
Throw new illegalaccessexception ("No such method ");
}
}
}