android checkbox是否选中,Android 中如何处理checkbox的选中、未选中

android checkbox是否选中,Android 中如何处理checkbox的选中、未选中xml页面布局android:orientation=”vertical”android:layout_width=”fill_parent”android:layout_height=”fill_parent”>android:text=”Plain”android:layout_width=”wrap_content”android:layout_height=”wrap_content…

大家好,又见面了,我是你们的朋友全栈君。

xml页面布局

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

>

android:text=”Plain”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

/>

android:text=”Bold”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:textStyle=”bold”

/>

android:text=”Serif”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:typeface=”serif”

/>

android:text=”Italic”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:textStyle=”italic”

/>

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:text=”获取CheckBox的值”

/>

—————————————————————————————-

10b0eb778b5424efde0e6143d6870955.gif

java类:

package com.zgct.activity;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

public class CheckBoxActivity extends Activity {

CheckBox plain_cb;

CheckBox serif_cb;

CheckBox italic_cb;

CheckBox bold_cb;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setTitle(“CheckBoxActivity”);

setContentView(R.layout.check_box);

find_and_modify_text_view();

}

private void find_and_modify_text_view(){

plain_cb = (CheckBox) findViewById(R.id.plain_cb);

serif_cb = (CheckBox) findViewById(R.id.serif_cb);

italic_cb = (CheckBox) findViewById(R.id.italic_cb);

bold_cb = (CheckBox) findViewById(R.id.bold_cb);

Button get_view_button = (Button)findViewById(R.id.get_view_button);

get_view_button.setOnClickListener(get_view_button_listener);

}

private Button.OnClickListener get_view_button_listener = new Button.OnClickListener(){

public void onClick(View v){

String r = “”;

if(plain_cb.isChecked()){

r = r + “,” + plain_cb.getText();

}

if(serif_cb.isChecked()){

r = r + “,” + serif_cb.getText();

}

if(bold_cb.isChecked()){

r = r + “,” + bold_cb.getText();

}

if(italic_cb.isChecked()){

r = r + “,” + italic_cb.getText();

}

setTitle(“Checked: ” + r);

}

};

}0b1331709591d260c1c78e86d0c51c18.png

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150577.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux 0.12 内核管理存储器

    Linux 0.12 内核管理存储器

    2022年1月1日
    51
  • 如何写软件项目技术标

    如何写软件项目技术标技术标作为一个初期评价软件供应商的重要标准之一,需要覆盖多方面的考虑因素,从需求的理解,到系统的设计,到项目的实施与管理,以及项目的验收与后期支持。那么我们如何来编写一个完整的技术标呢?第一,项目概述   项目情况的一个综合介绍,这是一个综述,通过这个综述说明项目的背景

    2022年5月11日
    66
  • mysql慢查询日志_sql慢查询日志

    mysql慢查询日志_sql慢查询日志1、显示慢日志是否开启showvariableslike‘%slow_query_log%’2、查询超过多少秒才记录showvariableslike‘%long_query_time%’3、配置分全局配置和配置文件的配置全局配置1)将slow_query_log全局变量设置为“ON”状态setglobalslow_query_log=‘ON’;2)查询超过1秒就记录setgloballong_query_time=13)设置慢查询日志存放的位置setg

    2022年10月11日
    4
  • 架构之业务架构[通俗易懂]

    架构之业务架构[通俗易懂]业务架构之产品经理的职责产品经理的职责用户的原始需求往往是零散和碎片化的,产品经理的职责就是:告诉用户,系统长什么样子;告诉开发,他要实现什么功能。产品经理定义了系统的外表。产品经理的职责:1、收集用户的原始需求,2、梳理成一个个业务流程,每个业务流程由多个业务步骤组成。一个业务步骤包含三部分的内容:输入、输出和业务功能。3、需求梳理好后,产品经理会把每个步骤具体化为页面原型。在原型中,会以直观的方式给出各个步骤的输入或输出,以及用户的操作过程,最后再把这些页面串起来,形成一个业

    2022年10月12日
    6
  • CSS加JS实现网页返回顶部功能

    CSS加JS实现网页返回顶部功能最近在设计自己的博客,前端页面在内容很多的时候往下拖动会有滚动条。通常我们都需要一个返回顶部的功能来实现快速来到网页顶部。当然实现方式不止一种,这里我采用的最实用的一种。使用CSS+Jquery方式代码量相对较少,容易理解。实现原理1.我们需要再DOM中添加自己的DIV,里面包含一个a标签,a标签里面包含两个img标签用于存放返回顶部的图片。2.添加必要的CSS样式3.然后…

    2022年7月15日
    17
  • 彻底关闭win10自动更新(针对已经关闭windows update项,但系统仍自动更新的问题)

    彻底关闭win10自动更新(针对已经关闭windows update项,但系统仍自动更新的问题)1、首先打开电脑服务项,找到Windowsupdate项,并双击打开属性一栏2、将启动类型替换为禁用3、点击上面的恢复,选择第一次失败后无操作。4、选择应用,并点击确定关闭。针对大部分电脑只进行上面的操作(关闭服务中的windowsupdate服务),win10仍然会自动更新,而且还会自动更改你刚才配置的启动类型,仍然自动启动(这很坑爹,我的电脑就是这样),这时需要你再进行下…

    2022年5月24日
    123

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号