- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Android控件之CheckBox、RadioButton用法实例分析由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了android控件之checkbox、radiobutton用法。分享给大家供大家参考。具体如下:
checkbox和radiobutton控件都只有选中和未选中状态,不同的是radiobutton是单选按钮,需要编制到一个radiogroup中,同一时刻一个radiogroup中只能有一个按钮处于选中状态.
以下为checkbox和radiobutton常用方法及说明 。
以下为单选按钮和复选按钮的使用方法 。
目录结构:
main.xml布局文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<scrollview xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
android:scrollbars=
"vertical"
>
<linearlayout android:orientation=
"vertical"
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
>
<!-- radiobutton控件演示 -->
<imageview android:id=
"@+id/imageview01"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:src=
"@drawable/bulb_on"
android:layout_gravity=
"center_horizontal"
/>
<radiogroup android:id=
"@+id/radiogroup"
android:orientation=
"horizontal"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
>
<radiobutton android:id=
"@+id/on"
android:text=
"开灯"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"true"
/>
<radiobutton android:id=
"@+id/off"
android:text=
"关灯"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</radiogroup>
<!-- checkbox控件演示 -->
<imageview android:id=
"@+id/imageview02"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:src=
"@drawable/bulb_on"
android:layout_gravity=
"center_horizontal"
/>
<checkbox android:id=
"@+id/checkbox"
android:text=
"开灯"
android:checked=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
/>
</linearlayout>
</scrollview>
|
cbrbactivity类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package
com.ljq.activity;
import
android.app.activity;
import
android.os.bundle;
import
android.widget.checkbox;
import
android.widget.compoundbutton;
import
android.widget.imageview;
import
android.widget.radiobutton;
import
android.widget.compoundbutton.oncheckedchangelistener;
public
class
cbrbactivity
extends
activity {
private
imageview imageview01=
null
;
private
imageview imageview02=
null
;
private
checkbox checkbox=
null
;
private
radiobutton on=
null
;
//开灯
@override
public
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate);
setcontentview(r.layout.main);
imageview01=(imageview)findviewbyid(r.id.imageview01);
imageview02=(imageview)findviewbyid(r.id.imageview02);
checkbox=(checkbox)findviewbyid(r.id.checkbox);
on=(radiobutton)findviewbyid(r.id.on);
on.setoncheckedchangelistener(listener);
checkbox.setoncheckedchangelistener(listener);
}
oncheckedchangelistener listener=
new
oncheckedchangelistener(){
public
void
oncheckedchanged(compoundbutton buttonview,
boolean
ischecked) {
if
(buttonview
instanceof
radiobutton){
imageview01.setimageresource(ischecked?r.drawable.bulb_on:r.drawable.bulb_off);
}
else
if
(buttonview
instanceof
checkbox){
checkbox.settext(ischecked?
"开灯"
:
"关灯"
);
imageview02.setimageresource(ischecked?r.drawable.bulb_on:r.drawable.bulb_off);
}
}
};
}
|
运行结果:
希望本文所述对大家的android程序设计有所帮助.
最后此篇关于Android控件之CheckBox、RadioButton用法实例分析的文章就讲到这里了,如果你想了解更多关于Android控件之CheckBox、RadioButton用法实例分析的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我一直在尝试使用 RadioButton 将另一个 RadioButton 变为可见。我是这个环境的新手,这是我的第一个 Windows Phone 应用程序。我的代码: private void
我有一个 GroupBox 和一堆 RadioButtons。当他们有焦点时,我可以使用向上/向下键来遍历它们。 但是,当我手动更改已选中的 RadioButton 并按向上/向下键时,迭代将从更改已
使用 WPF 和 MVVM 模式,我得到了一个动态填充单选按钮的列表框。
我有一个带有四个单选按钮的 RadioGroup,我让它们使用 4 的权重和在屏幕上均匀地隔开它们。这很好用,但结果是图形左对齐,而不是在每个单选按钮的中心。有没有办法将图形移动到中心?我尝试了重力中
我有 3 个单选按钮,用于对 API 中的不同数据进行排序。在每个单选按钮上,如果我按另一个单选按钮,单选按钮值就会消失,如下所示: 和 。我尝试使用属性绑定(bind) [value],但这导致了错
假设我有几个单选按钮和一些自定义对象作为数据源。 举个例子 public enum SomeModeType { firstMode = 10, secondMode = 20,
我正在尝试设置对单选组中第一个单选按钮的选择。在深入探讨这个问题之前,我需要指出问题仅发生在 API <= 16 中。当在模拟器或真实设备中运行 API 17 或更高版本时,一切正常。 它应该做什么
对于android编程,我有一个RadioGroup,其中包含一些RadioButtons。我只想从按钮获取文本,而不需要获取 RadioButton 的 id。
我编写了以下脚本,一旦单击要取消选中的其他复选框,它的工作正常,但是一旦我单击 tabkey,它就不会被选中或取消选中,它只会获得焦点, 脚本 function toggle(obj) { i
我有一个单选组,我可以在其中以编程方式添加单选按钮。这一切都是在 onCreateView() 方法中完成的,因此每次从后台堆栈重新创建 fragment 时都应该重做。我遇到的问题是,当我在开始时使
假设我在 RadioButtonGroup 中有一些 RadioButton。我单击其中一个,我意识到我不应该提交表单,相反,我只想触发取消操作并返回到我未选择的原始状态。我该怎么做? 最佳答案 想通
在我的布局中,我有一个 AppCompatRadioButton。使用 app:buttonTint 我将按钮设置为白色。如果我检查了 AppCompatRadioButton,圆圈的填充颜色也是白色
我正在开始使用 JavaFX,并且我已经构建了一个小俄罗斯方 block 游戏。现在一切正常,但最后我决定添加一组单选按钮来选择难度 - 这里我遇到了一个问题:突然LEFT/RIGHT/UP/DOWN
我的 RadioGroup 中的 RadioButton 在我取消选中它们或单击组中的另一个 RadioButton 后留下一个黑色的选中圆圈。我该如何防止这种情况发生?
在每个场景中,我都有多个切换组,每个切换组有两个单选按钮。无论我首先选择哪个场景上的哪个 RadioButton,听众都不会明白。它仍然为空,而不是保存设置的用户数据。如果我按第二次,它就会起作用。
我有一个有 2 个字段的应用程序:company_name 和 logo,我在 Model 的 Form 中显示像单选按钮这样的公司,但我想显示 logo 公司而不是公司标签(公司名称) 任何的想法
所以我想在我的应用程序中添加一个计算器。用户将首先单击适用于英制和公制单位的 RadioButton,然后根据用户单击的单选按钮,将出现其中一种布局。 如您所知,英制单位有英尺和英寸,为此我需要两个
我正在开发一个订单应用程序。如果实际时间在开放时间,则应将 rdi_now 的可见性设置为可见,否则设置为消失,因此用户在关闭时间只有选择预购的选项,但 rdi_preorder 没有做应该做的事情。
我在尝试单击时检查和取消选中单选按钮时遇到了一些问题。 我想做的是,当加载 Activity 时,单选按钮默认设置为选中。当用户按下选中的单选按钮时,我将单选按钮设置为取消选中并清空 TextView
我有三个单选按钮,我希望根据我单击的复选框上传我的 GUI。 我引用过本指南:http://docs.oracle.com/javafx/2/ui_controls/radio-button.htm这
我是一名优秀的程序员,十分优秀!