Android checkBox
CheckBox为复选框
<TextView android:id="@+id/tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你会哪些移动开发:" android:textSize="20dp"/> <CheckBox android:id="@+id/cb_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Android" android:textSize="20dp" android:layout_below="@id/tv_1" android:layout_marginTop="15dp" /> <CheckBox android:id="@+id/cb_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Mac" android:textSize="20dp" android:layout_below="@id/cb_1" android:layout_marginTop="15dp" /> <CheckBox android:id="@+id/cb_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HS" android:textSize="20dp" android:layout_below="@id/cb_2" android:layout_marginTop="15dp" /> <CheckBox android:id="@+id/cb_4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="其他" android:textSize="20dp" android:layout_below="@id/cb_3" android:layout_marginTop="15dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/cb_4" android:orientation="vertical" android:layout_marginTop="15dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="你的兴趣是:" android:textSize="20dp"/> <CheckBox android:id="@+id/cb_5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="编程" android:textSize="20dp" android:layout_marginTop="15dp" android:button="@drawable/selectcheckbox" /> <CheckBox android:id="@+id/cb_6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="做饭" android:textSize="20dp" android:layout_marginTop="15dp" android:button="@drawable/selectcheckbox" /> </LinearLayout>
设置点击事件
public class CheckBox1 extends AppCompatActivity { private CheckBox mcb_5; private CheckBox mcb_6; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_check_box); mcb_5 = (CheckBox) findViewById(R.id.cb_5); mcb_6 = (CheckBox) findViewById(R.id.cb_6); mcb_5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Toast.makeText(CheckBox1.this,b?"编程选中":"编程未选中",Toast.LENGTH_SHORT).show(); } }); mcb_6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Toast.makeText(CheckBox1.this,b?"做饭选中":"做饭未选中",Toast.LENGTH_SHORT).show(); } }); } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!