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(多選,全選,反選)具體實現(xiàn)方法
- android RadioButton和CheckBox組件的使用方法
- Android在listview添加checkbox實現(xiàn)原理與代碼
- 詳解Android Checkbox的使用方法
- android開發(fā)教程之自定義控件checkbox的樣式示例
- Android控件系列之CheckBox使用介紹
- Android中ListView + CheckBox實現(xiàn)單選、多選效果
- Android中ListView結(jié)合CheckBox實現(xiàn)數(shù)據(jù)批量選擇(全選、反選、全不選)
- Android中自定義Checkbox組件實例
- Android中CheckBox復選框控件使用方法詳解
相關文章
Android性能優(yōu)化之弱網(wǎng)優(yōu)化詳解
這篇文章主要為大家介紹了Android性能優(yōu)化之弱網(wǎng)優(yōu)化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10android實現(xiàn)RecyclerView列表單選功能
這篇文章主要為大家詳細介紹了android實現(xiàn)RecyclerView列表單選功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07Android實現(xiàn)環(huán)信修改頭像和昵稱
這篇文章主要為大家詳細介紹了Android實現(xiàn)環(huán)信修改頭像和昵稱,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02Android使用自定義ImageView實現(xiàn)圓形圖片效果
本篇文章主要介紹了Android使用自定義ImageView實現(xiàn)圓形圖片效果,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05