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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • django 聚合函数_聚合函数和非聚合函数

    django 聚合函数_聚合函数和非聚合函数前言orm模型中的聚合函数跟MySQL中的聚合函数作用是一致的,也有像Sum、Avg、Count、Max、Min,接下来我们逐个介绍聚合函数所有的聚合函数都是放在django.db.models

    2022年7月29日
    5
  • python——初识python(安装pycharm和ipython)

    python——初识python(安装pycharm和ipython)Python之编译安装三部曲编译安装三部曲:configure   编译make    安装makeinstall  安装成包解压压缩包tarzxfPython-3.6.4.tgz-C/opt/安装编译过程需要的依赖性(进入到安装包路径下)cd/opt/cdPython-3.6.4/yuminstallgcc-y安装yum…

    2022年8月26日
    3
  • java多线程面试题大全_java多线程面试题_线程并发面试题

    java多线程面试题大全_java多线程面试题_线程并发面试题1、什么是线程?线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位。程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速。比如,如果一个线程完成一个任务要100毫秒,那么用十个线程完成改任务只需10毫秒。2、线程和进程有什么区别?线程是进程的子集,一个进程可以有很多线程,每条线程并行执行不同的任务。不同的进程使用不同的内存空间,而所有的线程共享一…

    2022年7月7日
    20
  • 制作opc服务器,力控服务器怎样做为OPC服务器,供其他OPC客户端程序访问

    制作opc服务器,力控服务器怎样做为OPC服务器,供其他OPC客户端程序访问publicvoidListAll(Guidcatid,outOpcServers[]serverslist){serverslist=null;Dispose();Guidguid=newGuid(13486D51-4821-11D2-A494-3CB306C10000);Typetypeoflist=Type.GetTypeFromCLSID(guid);OPCL…

    2022年6月20日
    31
  • 数据库索引的实现原理

    数据库索引的实现原理

    2022年2月24日
    58
  • 抖音、吃鸡、王者荣耀:你的自律,是如何被顶级产品经理一步一步毁掉的

    抖音、吃鸡、王者荣耀:你的自律,是如何被顶级产品经理一步一步毁掉的文章概要01你的沉迷跟这个时代有关这是个特别容易沉迷的时代。抖音、煲剧、王者荣耀、吃鸡游戏……你的时间和注意力悄悄被它们偷走,却从不说再见。或许你也纳闷,自己的自制力怎么这么差了?但我想说,这事可能不完全怪你。《欲罢不能:刷屏时代如何摆脱行为上瘾》分享到:你的沉迷跟这个时代有关。作者亚当·奥尔特,是普林斯顿大学的心理学博士。他在这本书里以大量科学研究为基础,揭示了一个细思极恐的真相…

    2022年6月10日
    34

发表回复

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

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