(3.5)HarmonyOS鸿蒙多按钮点击事件
生活随笔
收集整理的這篇文章主要介紹了
(3.5)HarmonyOS鸿蒙多按钮点击事件
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
多按鈕的點(diǎn)擊事件其實(shí)與只有一個(gè)是類(lèi)似的,只不過(guò)要在調(diào)用 onClick()時(shí)進(jìn)行判斷,判斷獲取到的component是誰(shuí)即可。
package com.example.yeman.slice;import com.example.yeman.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.Text;public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {Text text1;Button login;Button register;@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);//1.找到文本框組件,按鈕組件text1 = (Text) findComponentById(ResourceTable.Id_text1);login = (Button) findComponentById(ResourceTable.Id_login);register = (Button) findComponentById(ResourceTable.Id_register);login.setClickedListener(this);register.setClickedListener(this);}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}@Overridepublic void onClick(Component component) {//先做一個(gè)判斷//判斷當(dāng)前點(diǎn)擊的是登錄按鈕還是注冊(cè)按鈕//component表示當(dāng)前點(diǎn)擊的組件if(component == login){//表示現(xiàn)在點(diǎn)擊的是登錄按鈕text1.setText("點(diǎn)擊了登錄按鈕");}else if(component == register){//表示現(xiàn)在點(diǎn)擊的是注冊(cè)按鈕text1.setText("點(diǎn)擊了注冊(cè)按鈕");}} }總結(jié)
以上是生活随笔為你收集整理的(3.5)HarmonyOS鸿蒙多按钮点击事件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 浦大喜奔app怎么取现(汉典浦字的基本解
- 下一篇: 计算机二级web题目(9.1)--综合选