final String handlerName = a.getString(attr);
08
if (handlerName != null) {
09
setOnClickListener(new OnClickListener() {
10
private Method mHandler;
11
12
public void onClick(View v) {
13
if (mHandler == null) {
14
try {
15
mHandler = getContext().getClass().getMethod(handlerName,
16
View.class);
17
} catch (NoSuchMethodException e) {
18
int id = getId();
19
String idText = id == NO_ID ? "" : " with id '"
20
+ getContext().getResources().getResourceEntryName(
21
id) + "'";
22
throw new IllegalStateException("Could not find a method " +
23
handlerName + "(View) in the activity "
24
+ getContext().getClass() + " for onClick handler"
25
+ " on view " + View.this.getClass() + idText, e);
26
}
27
}
28
29
try {
30
mHandler.invoke(getContext(), View.this);
31
} catch (IllegalAccessException e) {
32
throw new IllegalStateException("Could not execute non "
33
+ "public method of the activity", e);
34
} catch (InvocationTargetException e) {
35
throw new IllegalStateException("Could not execute "
36
+ "method of the activity", e);
37
}
38
}
39
});