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和IOS的瀏覽器中檢測(cè)是否安裝某個(gè)客戶端的方法
這篇文章主要介紹了Android和IOS的瀏覽器中檢測(cè)是否安裝某個(gè)客戶端的方法,需要的朋友可以參考下2014-06-06
Android利用EditText如何實(shí)現(xiàn)搜索框詳解
EditText 在開發(fā)中也是經(jīng)常用到的控件,也是一個(gè)比較必要的組件,下面這篇文章主要給大家介紹了關(guān)于Android利用EditText如何實(shí)現(xiàn)搜索框的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07
Android自定義View實(shí)現(xiàn)照片裁剪框與照片裁剪功能
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)照片裁剪框與照片裁剪功能的相關(guān)資料,需要的朋友可以參考下2016-07-07
Android控件系列之RadioButton與RadioGroup使用方法
本文介紹了Android中如何使用RadioGroup和RadioButton,對(duì)比了RadioButton和CheckBox的區(qū)別,并實(shí)現(xiàn)了自定義的RadioGroup中被選中RadioButton的變更監(jiān)聽事件2012-11-11
Android實(shí)現(xiàn)樹形層級(jí)ListView
這篇文章主要介紹了Android實(shí)現(xiàn)樹形層級(jí)ListView的相關(guān)資料,需要的朋友可以參考下2016-02-02
源碼解析Android Jetpack組件之ViewModel的使用
Jetpack 是一個(gè)豐富的組件庫,它的組件庫按類別分為 4 類,分別是架構(gòu)(Architecture)、界面(UI)、 行為(behavior)和基礎(chǔ)(foundation)。本文將從源碼和大家講講Jetpack組件中ViewModel的使用2023-04-04
Android中的layout_gravity與gravity屬性詳解
layout_gravity和gravity是Android開發(fā)中用于控制視圖布局和對(duì)齊方式的兩個(gè)屬性,layout_gravity用于指定視圖在父容器中的對(duì)齊方式,而gravity用于指定視圖內(nèi)部?jī)?nèi)容的對(duì)齊方式,本文介紹Android中的layout_gravity與gravity屬性,感興趣的朋友一起看看吧2025-03-03
Android實(shí)現(xiàn)自定義手勢(shì)和識(shí)別手勢(shì)的功能
這篇文章主要介紹了Android實(shí)現(xiàn)自定義手勢(shì)和識(shí)別手勢(shì)的功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
Android開發(fā)實(shí)現(xiàn)簡(jiǎn)單的觀察者與被觀察者示例
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)簡(jiǎn)單的觀察者與被觀察者,簡(jiǎn)單描述了觀察者模式的概念、原理并結(jié)合實(shí)例形式分析了Android實(shí)現(xiàn)觀察者模式的簡(jiǎn)單操作技巧,需要的朋友可以參考下2017-11-11

