Android学习路之RadioButton&Checkbox

本文详细介绍了Android开发中RadioButton(单选按钮)与CheckBox(复选框)的使用方法,包括XML布局配置及Java代码实现选择状态监听与获取选中项的功能。

RadioButton(单选按钮)&Checkbox(复选框)

1)RadioButton(单选按钮)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请选择性别"
        android:textSize="23dp"
        />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/btnMan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:checked="true"/>

        <RadioButton
            android:id="@+id/btnWoman"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""/>
    </RadioGroup>

    <Button
        android:id="@+id/btnpost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="提交"/>

</LinearLayout>
运行效果:



2)CheckBox(复选框)

public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{

    private CheckBox cb_one;
    private CheckBox cb_two;
    private CheckBox cb_three;
    private Button btn_send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        cb_one = (CheckBox) findViewById(R.id.cb_one);
        cb_two = (CheckBox) findViewById(R.id.cb_two);
        cb_three = (CheckBox) findViewById(R.id.cb_three);
        btn_send = (Button) findViewById(R.id.btn_send);

        cb_one.setOnCheckedChangeListener(this);
        cb_two.setOnCheckedChangeListener(this);
        cb_three.setOnCheckedChangeListener(this);
        btn_send.setOnClickListener(this);

    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if(compoundButton.isChecked()) Toast.makeText(this,compoundButton.getText().toString(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {
        String choose = "";
        if(cb_one.isChecked())choose += cb_one.getText().toString() + "";
        if(cb_two.isChecked())choose += cb_two.getText().toString() + "";
        if(cb_three.isChecked())choose += cb_three.getText().toString() + "";
        Toast.makeText(this,choose,Toast.LENGTH_SHORT).show();
    }
}
运行效果:



下载前必看:https://pan.quark.cn/s/a4b39357ea24 在当前快节奏的社会背景下,快递代拿服务已演变为日常生活中不可或缺的组成部分。 基于SSM(Spring、SpringMVC、MyBatis)框架的Java快递代拿系统,正是为了迎合这一需求而进行设计和构建的。 接下来将系统性地阐述系统的功能特性、架构布局以及具体的实现步骤。 1. **系统功能**: - **用户模块**:用户具备注册账户、登录验证、提交订单、挑选快递代取服务以及完成线上支付的各项操作。 - **订单模块**:当客户提交订单后,系统将自动生成包含快递种类、取件地点、送件地点等详细信息的订单记录,用户能够实时追踪订单进展,如待接单、处理中、已完成等不同阶段。 - **管理员模块**:管理员享有高级操作权限,能够接收并处理订单,执行订单的添加、删除、查询和修改等操作,同时负责处理用户的疑问和投诉。 - **支付模块**:系统整合了在线支付接口,支持用户通过第三方支付渠道完成支付,以此保障交易过程的安全性和便利性。 2. **技术选型**: - **SSM框架**:Spring主要用于依赖注入和事务控制,SpringMVC负责处理客户端请求与服务器响应,MyBatis作为数据持久化层,执行数据库交互,三者协同工作构建了一个高效且灵活的开发环境。 - **MySQL数据库**:系统内所有数据,包括用户资料、订单详情、支付历史等,均存储于MySQL数据库中,其卓越的查询性能和稳定性为系统提供了可靠的数据基础。 3. **系统架构**: - **前端**:运用HTML、CSS和JavaScript进行界面设计,可能还会引入Vue.js或jQuery等库以增强用户体验。 - **后端*...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值