单选布局详细讲解含监听
在androlua开发应用的过程中我们经常会使用单选布局,如上预览图
那么怎么写这个单选布局呢,单选布局里面的按钮内容又如何监听获取呢?单选控件 RadioGroup
单选按钮控件 RadioButton布局写法如下:
--在下面布局中RadioGroup为单选布局 RadioButton为单选布局的按钮
dxbj={
ScrollView,
VerticalScrollBarEnabled=false,
{--滚动布局下必须有线性竖直布局
LinearLayout,
orientation="vertical",
layout_width="fill",
layout_height="fill",
{
RadioGroup,--单选控件
orientation="vertical",--布局方向
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
id="rip";
gravity="center",--置中
layout_marginLeft="10%w",
layout_marginTop="100dp";
{
RadioButton,--单选按钮控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
text="单选布局测试文本1",--文本内容
id="rip_1";
--checked=true,--是否选中
},
{
RadioButton,--单选按钮控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
text="单选布局测试文本2",--文本内容
id="rip_2";
--checked=true,--是否选中
},
{
RadioButton,--单选按钮控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
text="单选布局测试文本3",--文本内容
--checked=true,--是否选中
id="rip_3";
},
{
RadioButton,--单选按钮控件
layout_width="fill",--布局宽度
layout_height="wrap",--布局高度
text="单选布局测试文本4",--文本内容
id="rip_4";
--checked=true,--是否选中
},
},--单选控件结束
},
}
activity.setContentView(loadlayout(dxbj))
写好布局之后 我们还需要给我们的单选控件设置监听
监听写法如下
--下面是单选布局的监听事件
rip.setOnCheckedChangeListener{--这里的rip是单选控件的ID
onCheckedChanged=function(v,e)
--这里的v是获取到当前的RadioButton(单选按钮)控件;
--这里的e是当前选中按钮的xml id值 等同于.getCheckedRadioButtonId()
--所以 单选控件ID.findViewById(e).getText() 就是当前你选中按钮的文本内容
print("您选择了 "..rip.findViewById(e).getText())
end
}
为了方便大家学习 小编还为大家准备了 fas & alp 模板供大家参考
下载地址:评论后可下载
此处内容已隐藏,评论后刷新即可查看!
吃吃吃
2021-02-16 16:46我现在就看看
好像
2021-02-15 20:32不错
魔眼
2021-02-14 21:18就等你了
万戈
2021-01-31 21:41可以
万戈
2021-01-31 10:19厉害
Sk
2021-01-23 18:12烈害66666
123
2020-10-25 13:10谢谢
aa
2020-09-23 21:29大佬nb
到底
2020-08-16 11:46还可以
cab
2020-08-14 21:48康康