本篇文章为大家展示了Android中怎么实现复选框,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
1.调用setOnCheckedChangeListener()方法,并把CompoundButton.OnCheckedChangeListener实例作为参数传入
2.在CompoundButton.OnCheckedChangeListener的onCheckedChanged()方法里,取得被选中Android复选框的实例
例程源码(Java)
CheckBox checkBox = (CheckBox) findViewById(id.checkBox); checkBox.setChecked(true); checkBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged( CompoundButton buttonView, boolean isChecked) { CheckBox checkBox = (CheckBox) buttonView; Log.v("Test", String.valueOf(checkBox.getText()) + " is " + String.valueOf(isChecked)); } });
例程源码(Resource)
< CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/test" />
上述内容就是Android中怎么实现复选框,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注天达云行业资讯频道。