开发者

How to define function in a string in Android?

开发者 https://www.devze.com 2022-12-28 07:59 出处:网络
I have an event handler that I want to be connected to a button through xml. Basically, I want to define it as a stri开发者_运维百科ng in my xml file, then use the property inspector to select the n

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

Basically, I want to define it as a stri开发者_运维百科ng 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?


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


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 :))

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号