美文网首页
CheckBox 复选框和多选框

CheckBox 复选框和多选框

作者: Luyc_Han | 来源:发表于2017-11-15 11:46 被阅读48次
布局:
   <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:checked="true"
        android:text="男"
        app:layout_constraintTop_toTopOf="parent"
        tools:layout_editor_absoluteX="36dp" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="女"
        tools:layout_editor_absoluteX="36dp"
        tools:layout_editor_absoluteY="114dp" />
实现:
      final CheckBox box1 = (CheckBox) findViewById(R.id.checkBox1);
        final CheckBox box2 = (CheckBox) findViewById(R.id.checkBox2);

        box1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                String text = box1.getText().toString();

                Log.i("tag", "onCheckedChanged: " + text);

            }
        });

效果图:


Untitled.gif

相关文章

网友评论

      本文标题:CheckBox 复选框和多选框

      本文链接:https://www.haomeiwen.com/subject/fzycvxtx.html