Android CheckBox 的使用案例分析
public class MainActivity extends Activity {
TextView tv;
CheckBox cb1;
CheckBox cb2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cb1 = (CheckBox) findViewById(R.id.checkbox1);
cb2 = (CheckBox) findViewById(R.id.checkbox2);
tv = (TextView) findViewById(R.id.textview1);
cb1.setOnCheckedChangeListener(cb);
cb2.setOnCheckedChangeListener(cb);
}
private CheckBox.OnCheckedChangeListener cb = new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String stv = getString(R.string.hoby);
String scb1 = getString(R.string.basketball);
String scb2 = getString(R.string.football);
if (cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb1 + "&&" + scb2);
} else if (cb1.isChecked() && !cb2.isChecked()) {
tv.setText(stv + ":" + scb1);
} else if (!cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb2);
} else {
tv.setText(stv);
}
}
};
如下是布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hoby" />
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/basketball" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/football" />
</LinearLayout>
- Android checkbox的listView(多選,全選,反選)具體實(shí)現(xiàn)方法
- android RadioButton和CheckBox組件的使用方法
- Android在listview添加checkbox實(shí)現(xiàn)原理與代碼
- 詳解Android Checkbox的使用方法
- android開發(fā)教程之自定義控件checkbox的樣式示例
- Android控件系列之CheckBox使用介紹
- Android中ListView + CheckBox實(shí)現(xiàn)單選、多選效果
- Android中ListView結(jié)合CheckBox實(shí)現(xiàn)數(shù)據(jù)批量選擇(全選、反選、全不選)
- Android中自定義Checkbox組件實(shí)例
- Android中CheckBox復(fù)選框控件使用方法詳解
相關(guān)文章
Android性能優(yōu)化之弱網(wǎng)優(yōu)化詳解
這篇文章主要為大家介紹了Android性能優(yōu)化之弱網(wǎng)優(yōu)化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Android?APP啟動(dòng)時(shí)間優(yōu)化介紹
大家好,本篇文章主要講的是Android?APP啟動(dòng)時(shí)間優(yōu)化介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12android實(shí)現(xiàn)RecyclerView列表單選功能
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)RecyclerView列表單選功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07Android編程實(shí)現(xiàn)等比例顯示圖片的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)等比例顯示圖片的方法,實(shí)例分析了Android等比例縮放圖片的具體步驟與相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11Android實(shí)現(xiàn)環(huán)信修改頭像和昵稱
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)環(huán)信修改頭像和昵稱,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02關(guān)于Android輸入法彈窗bug的優(yōu)雅處理
在Android應(yīng)用中,當(dāng)跳轉(zhuǎn)到某個(gè)Activity時(shí),該Activity顯示頁(yè)面的EditText獲得焦點(diǎn),在某些機(jī)器中會(huì)觸發(fā)軟鍵盤的自動(dòng)彈出,這篇文章主要給大家介紹了關(guān)于Android輸入法彈窗bug的優(yōu)雅處理,需要的朋友可以參考下2021-10-10Android使用自定義ImageView實(shí)現(xiàn)圓形圖片效果
本篇文章主要介紹了Android使用自定義ImageView實(shí)現(xiàn)圓形圖片效果,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-05-05