壹影博客.
我在下午4点钟开始想你
单选布局详细讲解含监听
  • 2020-7-30日
  • 28评论
  • 2391围观

单选布局详细讲解含监听

在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 模板供大家参考

下载地址:评论后可下载

此处内容已隐藏,评论后刷新即可查看!

发表评论

你爸

Lv.1 @回复 #26

牛逼

一个名字

Lv.2 @回复 #25

学习一下

北梦

Lv.1 @回复 #24

谢谢

s

Lv.1 @回复 #23

学习下

.

Lv.1 @回复 #22

大佬

Schwi

Lv.1 @回复 #21

学学布局

bao123456

Lv.2 @回复 #20

surl=Uri.parse(webView.url)
url_main=surl.authority--网址域名部分
url_scheme=surl.scheme--http, https, ftp或其他外部应用的scheme
url_path=surl.path--路径
url_query=surl.query--关键词部分
url_frag=surl.fragment
url_host=surl.host--主机
对话框()
.设置标题("网页链接信息")
.设置消息(url_main.."\n"..url_scheme)--如果值为nil连接在一起会报错哦
.设置积极按钮("OK")
.显示()

bao123456

Lv.2 @回复 #19

import "android.content.*"
  text="枫途整理工程"
  intent=Intent(Intent.ACTION_SEND);
  intent.setType("text/plain");
  intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
  intent.putExtra(Intent.EXTRA_TEXT, text);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  activity.startActivity(Intent.createChooser(intent

翻翻

Lv.1 @回复 #18

反飞动

and

Lv.2 @回复 #17

厉害