1.多选按钮(checkBox)的基本概念、
2.<ChecBox/>与CheckBox
3.OnClickListener与OnCheckedChangeListener监听器
//==============================
1.在XML文件当中使用<Check/>标签
2.在代码当中使用CheckBox的对象表示
//======================
<CheckBox
android:id = "@+id/eatId"
/>
alt+"/"快捷键
/
->MainActivity
private CheckBox eatBox;
private CheckBox sleepBox;
private CheckBox dotaBox;
导入一下
->onCreate()
eatBox = (CheckBox)findViewById(R.id.eatId);
OnBoxClickListener listener = new OnBoxClickListener();
eatBox.setOnClickListener(listener);
//=================
绑定监听器
class OnBoxClickListener implements OnClickListener{
//接口不是类需要实现它
@Overide
public void onClick(View view)
{
// view.getId();
if(view.getId()==R.id.eatId)
{
}
//===============
Check box = (CheckBox)view;
box.isChecked();//返回当前按钮是不是被选中
System.out.println("Checkbox is clicked");
}
}
//================================
新监听器
class CheckBoxListener implements OnCheckChangeLisener {
//导入包 import android.widget.CompoundButton.OnCheckedChangeListener;
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
{
}
}
//==================
CheckBoxListener listener = new CheckBoxListener();
eatBox.setOnCheckedChangeListener(listener);