复选框ChekcBox

来源:互联网 发布:eva分析软件 编辑:程序博客网 时间:2024/05/29 09:17

复选框ChekcBox

<CheckBox    android:id="@+id/checkBox_music"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="音乐" /><CheckBox    android:id="@+id/checkBox_history"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="历史" /><CheckBox    android:id="@+id/checkBox_art"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="美术" />
@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        // 关联布局文件        setContentView(R.layout.activity_main);        mCheckBoxArt = (CheckBox) findViewById(R.id.checkBox_art);        mCheckBoxHistory = (CheckBox) findViewById(R.id.checkBox_history);        mCheckBoxMusic = (CheckBox) findViewById(R.id.checkBox_music);        myCheckBoxSelected = new MyCheckBoxSelected();        mCheckBoxArt.setOnCheckedChangeListener(myCheckBoxSelected);        mCheckBoxHistory.setOnCheckedChangeListener(myCheckBoxSelected);        mCheckBoxMusic.setOnCheckedChangeListener(myCheckBoxSelected);    }    class MyCheckBoxSelected implements OnCheckedChangeListener {        @Override        public void onCheckedChanged(CompoundButton buttonView,                boolean isChecked) {            if (isChecked) {                String text = buttonView.getText().toString();                Log.e("选中了", text);            }        }    }

这里写图片描述

0 0