views:

80

answers:

2

I have an event handler that I want to be connected to a button through xml.

Basically, I want to define it as a string in my xml file, then use the property inspector to select the name of the handler for my button (the "on Click" property).

How do I define a call to the function in the string?

A: 

You can't can attach a function from XML.
What you do is create a layout, inflate it from Java code, find the button by id and attach a function that will be called on click.
This is covered in introductory tutorials.

EDIT:
As pointed out by Romain Guy, http://developer.android.com/intl/de/reference/android/view/View.html#attr_android:onClick
(but I'd say it's crazy anyways :))

alex
Actually you can since Donut: android:onClick="myClickHandler" and you must have a public void myClickHandler(View v) method in your Activity.
Romain Guy
+1  A: 

It's "Easier click listeners" section here http://android-developers.blogspot.com/2009/10/ui-framework-changes-in-android-16.html

Fedor