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


相关推荐

  • 在Spring Boot中使用Spring-data-Jpa,findOne()方法无效

    在学习SpringBoot过程中,发现在使用Jpa进行数据库操作的时候,Jpa的findOne()根据主键查数据方法无效了,让我很纳闷,之后查了一下百度,发现是SpringBoot版本问题 使用的版本是SpringBoot 2.0.4既然找不到findOne()方法,可以找一下别的嘛,然后发现里面有个叫findById()的方法,有点像了。。。。 但是神奇的发现,他的返回类型是…

    2021年11月30日
  • C++在stack的deque实现

    C++在stack的deque实现

    2021年9月7日
  • Symfony2 细节小计4

    Symfony2 细节小计4

    2021年9月10日
  • 291312a_tải nhạc

    291312a_tải nhạc一个序列长度是L,每个位置取1的概率是p,取0的概率是1-p

    2022年11月1日
  • word在试图打开文件时遇到错误,解决办法

    word在试图打开文件时遇到错误,解决办法有时候下载或别人发给你的文件用自己的电脑上的Word打不开,会出现下面的提示怎么办呢查后找到了一种解决办法:打开Word,选择-文件-选项点击左侧的信任中心按钮,然后选择右侧的信任中心设置进入信任中心后点击左侧的受保护视图选项卡,默认是三个选项都被选中的,如图取消勾选第一个选项“为来自Internet的文件启用受保护的视图”,点击确定后推出,然后重新打开…

    2022年4月29日
  • 什么是cs什么是bs_bs代替CS

    什么是cs什么是bs_bs代替CSC/S结构,即Client/Server(客户机/服务器)结构,是大家熟知的软件系统体系结构,通过将任务合理分配到Client端和Server端,降低了系统的通讯开销,可以充分利用两端硬件环境的优势。早期的软件系统多以此作为首选设计标准。。 B/S结构,即Browser/Server(浏览器/服务器)结构,是随着Internet技术的兴起,对C/S结构的一种变化或者改进的结构。在这种结构下

    2022年9月9日

发表回复

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

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