Android 多选框

package com.example.allandreverse;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import android.os.Bundle;import android.app.Activity;import android.content
摘要由CSDN通过智能技术生成
package com.example.allandreverse;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private ListView list_view;
    private CheckAdapter checkAdapter;
    private CheckBox allBox;
    private Button reverse;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        list_view = (ListView)findViewById(R.id.list_view);
        allBox = (CheckBox)findViewById(R.id.all);
        reverse = (Button)findViewById(R.id.reverse);
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio中,可以使用多选框来实现用户可以选择多个选项的功能。以下是一个示例代码来演示如何在Android Studio中创建多选框: 1. 首先,在XML布局文件中添加一个多选框组件: ```xml <CheckBox android:id="@+id/checkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 1" /> <CheckBox android:id="@+id/checkbox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 2" /> <CheckBox android:id="@+id/checkbox3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Option 3" /> ``` 2. 在Java代码中,获取多选框组件的引用,并设置一个点击事件监听器来处理用户的选择: ```java CheckBox checkbox1 = findViewById(R.id.checkbox1); CheckBox checkbox2 = findViewById(R.id.checkbox2); CheckBox checkbox3 = findViewById(R.id.checkbox3); checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // 处理选项1的选择状态变化 if (isChecked) { // 选中状态 Toast.makeText(MainActivity.this, "Option 1 selected", Toast.LENGTH_SHORT).show(); } else { // 未选中状态 Toast.makeText(MainActivity.this, "Option 1 unselected", Toast.LENGTH_SHORT).show(); } } }); checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // 处理选项2的选择状态变化 if (isChecked) { // 选中状态 Toast.makeText(MainActivity.this, "Option 2 selected", Toast.LENGTH_SHORT).show(); } else { // 未选中状态 Toast.makeText(MainActivity.this, "Option 2 unselected", Toast.LENGTH_SHORT).show(); } } }); checkbox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // 处理选项3的选择状态变化 if (isChecked) { // 选中状态 Toast.makeText(MainActivity.this, "Option 3 selected", Toast.LENGTH_SHORT).show(); } else { // 未选中状态 Toast.makeText(MainActivity.this, "Option 3 unselected", Toast.LENGTH_SHORT).show(); } } }); ``` 这样,当用户选择或取消选择多选框时,会显示相应的Toast消息来提示用户选择的状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值