summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/current.xml11
-rw-r--r--core/java/android/view/View.java32
-rw-r--r--core/res/res/values/attrs.xml7
-rw-r--r--core/res/res/values/public.xml1
4 files changed, 51 insertions, 0 deletions
diff --git a/api/current.xml b/api/current.xml
index 93b3273c6b25..5080ca3e5906 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -5344,6 +5344,17 @@
visibility="public"
>
</field>
+<field name="onClick"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843375"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="oneshot"
type="int"
transient="false"
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 894045aea07f..07c56ee9864c 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -62,6 +62,8 @@ import com.android.internal.view.menu.MenuBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.ref.SoftReference;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
/**
* <p>
@@ -1874,6 +1876,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
case R.styleable.View_minHeight:
mMinHeight = a.getDimensionPixelSize(attr, 0);
break;
+ case R.styleable.View_onClick:
+ final String handlerName = a.getString(attr);
+ if (handlerName != null) {
+ setOnClickListener(new OnClickListener() {
+ private Method mHandler;
+
+ public void onClick(View v) {
+ if (mHandler == null) {
+ try {
+ mHandler = getContext().getClass().getMethod(handlerName,
+ View.class);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("Could not find a method " +
+ handlerName + "(View) in the activity", e);
+ }
+ }
+
+ try {
+ mHandler.invoke(getContext(), View.this);
+ } catch (IllegalAccessException e) {
+ throw new IllegalStateException("Could not execute non "
+ + "public method of the activity", e);
+ } catch (InvocationTargetException e) {
+ throw new IllegalStateException("Could not execute "
+ + "method of the activity", e);
+ }
+ }
+ });
+ }
+ break;
}
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 3d7f4066b393..633a831f0b18 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1165,6 +1165,13 @@
enabled for events such as long presses. -->
<attr name="hapticFeedbackEnabled" format="boolean" />
+ <!-- Name of the method in this View's context to invoke when the view is
+ clicked. This name must correspond to a public method that takes
+ exactly one parameter of type View. For instance, if you specify
+ <code>android:onClick="sayHello"</code>, you must declare a
+ <code>public void sayHello(View v)</code> method of your context
+ (typically, your Activity.)-->
+ <attr name="onClick" format="string" />
</declare-styleable>
<!-- Attributes that can be used with a {@link android.view.ViewGroup} or any
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 072f0c3301af..9e4c6a97b292 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1096,6 +1096,7 @@
<public type="attr" name="density" id="0x0101026c" />
<public type="attr" name="searchSuggestThreshold" id="0x0101026d" />
<public type="attr" name="includeInGlobalSearch" id="0x0101026e" />
+ <public type="attr" name="onClick" id="0x0101026f" />
<public type="anim" name="anticipate_interpolator" id="0x010a0007" />
<public type="anim" name="overshoot_interpolator" id="0x010a0008" />