日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

android:onClick attribute

發(fā)布時(shí)間:2024/4/15 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android:onClick attribute 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文以Button為例進(jìn)行介紹

1》XML文件代碼如下:

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send"android:onClick="sendMessage" />

The android:onClick attribute’s value, "sendMessage", is the name of a method in your activity that the system calls when the user clicks the button.

2》Open the Activity class (located in the project'ssrc/ directory) and add the corresponding method:

/** Called when the user clicks the Send button */ public void sendMessage(View view) {// Do something in response to button }


注意:

In order for the system to match this method to the method name given to android:onClick, the signature must be exactly as shown. Specifically, the method must:(該方法必須全部滿足以下三個(gè)條件:)
?Be public.(public)
?Have a void return value.(返回值為void)
?Have a View as the only parameter (this will be the View that was clicked).(ps:有且僅有一個(gè)參數(shù)類型為View的參數(shù),這一點(diǎn)特別重要,否則點(diǎn)擊該按鈕時(shí),不會(huì)調(diào)用該方法。)


這也是有時(shí)候明明指定了android:onClick屬性,并且Activity中也實(shí)現(xiàn)了對(duì)應(yīng)的方法,但是實(shí)際執(zhí)行的時(shí)候就是沒有執(zhí)行指定的方法的原因。仔細(xì)看一下你的方法是否同時(shí)滿足以上三個(gè)條件!!!




總結(jié)

以上是生活随笔為你收集整理的android:onClick attribute的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。