本文介紹了如何檢查是否在其 onClick 方法中檢查了 android 復(fù)選框(在 XML 中聲明)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在 android 中有一個(gè)復(fù)選框,其中包含以下 XML:
I have a checkbox in android which has the following XML:
<CheckBox
android:id="@+id/item_check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="itemClicked" />
這是我的 Activity 類中的 onClick() 方法.
This is my onClick() method in my Activity class.
public void itemClicked(View v) {
//code to check if this checkbox is checked!
}
我知道我們可以創(chuàng)建復(fù)選框的對(duì)象并為其分配 id.但是通過 XML 聲明 onClick
方法時(shí),有沒有更好的方法來實(shí)現(xiàn)該功能?
I am aware that we can create an object of the checkbox and assign id to it. But is there a better way to achieve the functionality when declaring onClick
method via XML?
推薦答案
試試這個(gè):
public void itemClicked(View v) {
//code to check if this checkbox is checked!
CheckBox checkBox = (CheckBox)v;
if(checkBox.isChecked()){
}
}
這篇關(guān)于如何檢查是否在其 onClick 方法中檢查了 android 復(fù)選框(在 XML 中聲明)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!