多项选择~checkbox的简单运用

来源:互联网 发布:矩阵奇异值和特征值 编辑:程序博客网 时间:2024/04/30 05:59
<CheckBox                    android:id="@+id/cb_tagType1_tag_food"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_marginLeft="16dp"                    android:button="@null"//取消对号框                    android:text="不要辣" />                <CheckBox                    android:id="@+id/cb_tagType2_tag_food"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_marginLeft="16dp"                    android:button="@null"                    android:text="少点辣" />

activity里


mType1=(CheckBox) findViewById(R.id.cb_tagType1_tag_food);mType2=(CheckBox) findViewById(R.id.cb_tagType2_tag_food);mType3=(CheckBox) findViewById(R.id.cb_tagType3_tag_food);mType4=(CheckBox) findViewById(R.id.cb_tagType4_tag_food);mType5=(CheckBox) findViewById(R.id.cb_tagType5_tag_food);mType6=(CheckBox) findViewById(R.id.cb_tagType6_tag_food);mType7=(CheckBox) findViewById(R.id.cb_tagType7_tag_food);
<pre class="java" name="code">mType1.setChecked(false);mType2.setChecked(false);mType3.setChecked(false);mType4.setChecked(false);mType5.setChecked(false);mType6.setChecked(false);mType6.setChecked(false);mType6.setChecked(false);mType1.setOnClickListener(this);mType2.setOnClickListener(this);mType3.setOnClickListener(this);mType4.setOnClickListener(this);mType5.setOnClickListener(this);mType6.setOnClickListener(this);mType7.setOnClickListener(this);

switch (v.getId()) {case R.id.cb_tagType1_tag_food:if (mType1.isChecked()) {mType1.setTextColor(Color.RED);;}else {mType1.setTextColor(Color.BLACK);}break;case R.id.cb_tagType2_tag_food:if (mType2.isChecked()) {mType2.setTextColor(Color.RED);;}else {mType2.setTextColor(Color.BLACK);}break;case R.id.cb_tagType3_tag_food:if (mType3.isChecked()) {mType3.setTextColor(Color.RED);;}else {mType3.setTextColor(Color.BLACK);}break;case R.id.cb_tagType4_tag_food:if (mType4.isChecked()) {mType4.setTextColor(Color.RED);;}else {mType4.setTextColor(Color.BLACK);}


就这么简单

0 0