自动发帖软件

标题: 苹果AIWROK实例单选按钮组类[RadioButtonGroup]完整综合示例 [打印本页]

作者: 发帖软件    时间: 6 小时前
标题: 苹果AIWROK实例单选按钮组类[RadioButtonGroup]完整综合示例
苹果AIWROK实例单选按钮组类[RadioButtonGroup]完整综合示例 苹果AIWROK实例单选按钮组类[RadioButtonGroup]完整综合示例 群发软件发帖工具


苹果AIWROK实例单选按钮组类[RadioButtonGroup]完整综合示例 群发软件发帖工具


  1. // 🎨UI-单选按钮组类[RadioButtonGroup]完整综合示例
  2. // 全面展示RadioButtonGroup的所有功能和方法
  3. // 🍎交流QQ群711841924群一,苹果内测群,528816639

  4. printl("=== RadioButtonGroup单选按钮组完整综合示例启动 ===");

  5. var tab = new TabView();

  6. tab.setTitles(["基础", "高级", "动态", "综合", "返回"]);

  7. tab.show(function() {
  8.     printl("TabView界面加载完成");
  9.    
  10.     // ====================== 第一页:基础方法演示 ======================
  11.     var basicPage = new Vertical();
  12.     basicPage.setSpacing(10);
  13.     basicPage.setBackgroundColor(255, 255, 255);
  14.    
  15.     var basicDesc = new Label();
  16.     basicDesc.setText("展示RadioButtonGroup的三个核心方法:setID、setDefultSelect、currentSelectedRadio");
  17.     basicDesc.setTextColor(100, 100, 100);
  18.     basicDesc.setFontSize(12);
  19.     basicDesc.setTextAlignment("center");
  20.     basicPage.addView(basicDesc);
  21.    
  22.     // 方法1:setID设置控件ID
  23.     var section1 = new Horizontal();
  24.     section1.setAlignment("center");
  25.     section1.setBackgroundColor(220, 220, 225);
  26.    
  27.     var section1Label = new Label();
  28.     section1Label.setText("方法1:setID设置控件ID");
  29.     section1Label.setTextColor(60, 60, 60);
  30.     section1Label.setFontSize(15);
  31.     section1.addView(section1Label);
  32.    
  33.     basicPage.addView(section1);
  34.    
  35.     var idDemoContainer = new Vertical();
  36.     idDemoContainer.setSpacing(10);
  37.     idDemoContainer.setBackgroundColor(255, 255, 255);
  38.    
  39.     var idDesc = new Label();
  40.     idDesc.setText("为单选按钮组设置唯一标识符,方便后续通过config读取配置");
  41.     idDesc.setTextColor(100, 100, 100);
  42.     idDesc.setFontSize(12);
  43.     idDemoContainer.addView(idDesc);
  44.    
  45.     var idCodeLabel = new Label();
  46.     idCodeLabel.setText("var rg = new RadioButtonGroup();\nrg.setID(\"abc\");\n// 读取使用\nconfig.getConfig(\"abc\");");
  47.     idCodeLabel.setTextColor(50, 50, 150);
  48.     idCodeLabel.setFontSize(11);
  49.     idCodeLabel.setBackgroundColor(245, 245, 255);
  50.     idDemoContainer.addView(idCodeLabel);
  51.    
  52.     var idDemoGroup = new RadioButtonGroup();
  53.     idDemoGroup.setID("demo_group_1");
  54.     idDemoGroup.setDefultSelect("选项A");
  55.    
  56.     // 创建单选按钮并关联到组
  57.     var optionA = new RadioButton();
  58.     optionA.setText("选项A");
  59.     optionA.setGroup(idDemoGroup);
  60.    
  61.     var optionB = new RadioButton();
  62.     optionB.setText("选项B");
  63.     optionB.setGroup(idDemoGroup);
  64.    
  65.     var optionC = new RadioButton();
  66.     optionC.setText("选项C");
  67.     optionC.setGroup(idDemoGroup);
  68.    
  69.     // 添加单选按钮到容器
  70.     var radioContainer = new Horizontal();
  71.     radioContainer.setSpacing(20);
  72.     radioContainer.addView(optionA);
  73.     radioContainer.addView(optionB);
  74.     radioContainer.addView(optionC);
  75.     idDemoContainer.addView(radioContainer);
  76.    
  77.     var idResultLabel = new Label();
  78.     idResultLabel.setText("控件ID已设置为:demo_group_1");
  79.     idResultLabel.setTextColor(0, 128, 0);
  80.     idResultLabel.setFontSize(12);
  81.     idDemoContainer.addView(idResultLabel);
  82.    
  83.     var idGetValueButton = new Button();
  84.     idGetValueButton.setText("获取当前值");
  85.     idGetValueButton.setColor(70, 130, 180);
  86.     idGetValueButton.setTextColor(255, 255, 255);
  87.     idGetValueButton.onClick(function() {
  88.         var selected = idDemoGroup.currentSelectedRadio();
  89.         var selectedText = selected ? selected.getText() : "未选择";
  90.         printl("方法1当前选中项: " + selectedText);
  91.         idResultLabel.setText("控件ID已设置为:demo_group_1,当前选中: " + selectedText);
  92.     });
  93.     idDemoContainer.addView(idGetValueButton);
  94.    
  95.     basicPage.addView(idDemoContainer);
  96.    
  97.     // 方法2:setDefultSelect设置默认值
  98.     var section2 = new Horizontal();
  99.     section2.setAlignment("center");
  100.     section2.setBackgroundColor(220, 220, 225);
  101.    
  102.     var section2Label = new Label();
  103.     section2Label.setText("方法2:setDefultSelect设置默认值");
  104.     section2Label.setTextColor(60, 60, 60);
  105.     section2Label.setFontSize(15);
  106.     section2.addView(section2Label);
  107.    
  108.     basicPage.addView(section2);
  109.    
  110.     var defaultDemoContainer = new Vertical();
  111.     defaultDemoContainer.setSpacing(10);
  112.     defaultDemoContainer.setBackgroundColor(255, 255, 255);
  113.    
  114.     var defaultDesc = new Label();
  115.     defaultDesc.setText("设置单选按钮组的默认选中项,初始化时自动选中指定选项");
  116.     defaultDesc.setTextColor(100, 100, 100);
  117.     defaultDesc.setFontSize(12);
  118.     defaultDemoContainer.addView(defaultDesc);
  119.    
  120.     var defaultCodeLabel = new Label();
  121.     defaultCodeLabel.setText("var rg = new RadioButtonGroup();\nrg.setID(\"性别\")\nrg.setDefultSelect(\"男\");");
  122.     defaultCodeLabel.setTextColor(50, 50, 150);
  123.     defaultCodeLabel.setFontSize(11);
  124.     defaultCodeLabel.setBackgroundColor(245, 245, 255);
  125.     defaultDemoContainer.addView(defaultCodeLabel);
  126.    
  127.     var genderGroup = new RadioButtonGroup();
  128.     genderGroup.setID("gender_group");
  129.     genderGroup.setDefultSelect("男");
  130.    
  131.     // 创建单选按钮并关联到组
  132.     var maleOption = new RadioButton();
  133.     maleOption.setText("男");
  134.     maleOption.setGroup(genderGroup);
  135.    
  136.     var femaleOption = new RadioButton();
  137.     femaleOption.setText("女");
  138.     femaleOption.setGroup(genderGroup);
  139.    
  140.     var otherOption = new RadioButton();
  141.     otherOption.setText("其他");
  142.     otherOption.setGroup(genderGroup);
  143.    
  144.     // 添加单选按钮到容器
  145.     var genderContainer = new Horizontal();
  146.     genderContainer.setSpacing(20);
  147.     genderContainer.addView(maleOption);
  148.     genderContainer.addView(femaleOption);
  149.     genderContainer.addView(otherOption);
  150.     defaultDemoContainer.addView(genderContainer);
  151.    
  152.     var defaultResultLabel = new Label();
  153.     defaultResultLabel.setText("默认选中项:男");
  154.     defaultResultLabel.setTextColor(0, 128, 0);
  155.     defaultResultLabel.setFontSize(12);
  156.     defaultDemoContainer.addView(defaultResultLabel);
  157.    
  158.     var defaultGetValueButton = new Button();
  159.     defaultGetValueButton.setText("获取当前值");
  160.     defaultGetValueButton.setColor(70, 130, 180);
  161.     defaultGetValueButton.setTextColor(255, 255, 255);
  162.     defaultGetValueButton.onClick(function() {
  163.         var selected = genderGroup.currentSelectedRadio();
  164.         var selectedText = selected ? selected.getText() : "未选择";
  165.         printl("方法2当前选中项: " + selectedText);
  166.         defaultResultLabel.setText("默认选中项:男,当前选中: " + selectedText);
  167.     });
  168.     defaultDemoContainer.addView(defaultGetValueButton);
  169.    
  170.     basicPage.addView(defaultDemoContainer);
  171.    
  172.     // 方法3:currentSelectedRadio当前选中的单选按钮
  173.     var section3 = new Horizontal();
  174.     section3.setAlignment("center");
  175.     section3.setBackgroundColor(220, 220, 225);
  176.    
  177.     var section3Label = new Label();
  178.     section3Label.setText("方法3:currentSelectedRadio获取当前选中项");
  179.     section3Label.setTextColor(60, 60, 60);
  180.     section3Label.setFontSize(15);
  181.     section3.addView(section3Label);
  182.    
  183.     basicPage.addView(section3);
  184.    
  185.     var currentDemoContainer = new Vertical();
  186.     currentDemoContainer.setSpacing(10);
  187.     currentDemoContainer.setBackgroundColor(255, 255, 255);
  188.    
  189.     var currentDesc = new Label();
  190.     currentDesc.setText("获取当前选中的单选按钮,用于读取用户选择或进行后续操作");
  191.     currentDesc.setTextColor(100, 100, 100);
  192.     currentDesc.setFontSize(12);
  193.     currentDemoContainer.addView(currentDesc);
  194.    
  195.     var currentCodeLabel = new Label();
  196.     currentCodeLabel.setText("new RadioButtonGroup().currentSelectedRadio()");
  197.     currentCodeLabel.setTextColor(50, 50, 150);
  198.     currentCodeLabel.setFontSize(11);
  199.     currentCodeLabel.setBackgroundColor(245, 245, 255);
  200.     currentDemoContainer.addView(currentCodeLabel);
  201.    
  202.     var currentGroup = new RadioButtonGroup();
  203.     currentGroup.setID("current_group");
  204.     currentGroup.setDefultSelect("选项1");
  205.    
  206.     // 创建单选按钮并关联到组
  207.     var option1 = new RadioButton();
  208.     option1.setText("选项1");
  209.     option1.setGroup(currentGroup);
  210.    
  211.     var option2 = new RadioButton();
  212.     option2.setText("选项2");
  213.     option2.setGroup(currentGroup);
  214.    
  215.     var option3 = new RadioButton();
  216.     option3.setText("选项3");
  217.     option3.setGroup(currentGroup);
  218.    
  219.     // 添加单选按钮到容器
  220.     var currentRadioContainer = new Horizontal();
  221.     currentRadioContainer.setSpacing(20);
  222.     currentRadioContainer.addView(option1);
  223.     currentRadioContainer.addView(option2);
  224.     currentRadioContainer.addView(option3);
  225.     currentDemoContainer.addView(currentRadioContainer);
  226.    
  227.     var currentButton = new Button();
  228.     currentButton.setText("获取当前选中项");
  229.     currentButton.setColor(70, 130, 180);
  230.     currentButton.setTextColor(255, 255, 255);
  231.     currentButton.onClick(function() {
  232.         var selected = currentGroup.currentSelectedRadio();
  233.         var selectedText = selected ? selected.getText() : "未选择";
  234.         printl("当前选中项: " + selectedText);
  235.         currentResultLabel.setText("当前选中项: " + selectedText);
  236.     });
  237.     currentDemoContainer.addView(currentButton);
  238.    
  239.     var currentResultLabel = new Label();
  240.     currentResultLabel.setText("当前选中项:选项1");
  241.     currentResultLabel.setTextColor(0, 128, 0);
  242.     currentResultLabel.setFontSize(12);
  243.     currentDemoContainer.addView(currentResultLabel);
  244.    
  245.     basicPage.addView(currentDemoContainer);
  246.    
  247.     // ====================== 第二页:高级应用演示 ======================
  248.     var advancedPage = new Vertical();
  249.     advancedPage.setSpacing(10);
  250.     advancedPage.setBackgroundColor(255, 255, 255);
  251.    
  252.     var advancedDesc = new Label();
  253.     advancedDesc.setText("展示RadioButtonGroup在实际应用场景中的使用方法");
  254.     advancedDesc.setTextColor(100, 100, 100);
  255.     advancedDesc.setFontSize(12);
  256.     advancedDesc.setTextAlignment("center");
  257.     advancedPage.addView(advancedDesc);
  258.    
  259.     // 应用1:用户设置界面
  260.     var appSection1 = new Horizontal();
  261.     appSection1.setAlignment("center");
  262.     appSection1.setBackgroundColor(220, 220, 225);
  263.    
  264.     var appSection1Label = new Label();
  265.     appSection1Label.setText("应用1:用户设置界面");
  266.     appSection1Label.setTextColor(60, 60, 60);
  267.     appSection1Label.setFontSize(15);
  268.     appSection1.addView(appSection1Label);
  269.    
  270.     advancedPage.addView(appSection1);
  271.    
  272.     var settingsContainer = new Vertical();
  273.     settingsContainer.setSpacing(12);
  274.     settingsContainer.setBackgroundColor(255, 255, 255);
  275.    
  276.     var settingsDesc = new Label();
  277.     settingsDesc.setText("使用RadioButtonGroup实现用户偏好设置");
  278.     settingsDesc.setTextColor(100, 100, 100);
  279.     settingsDesc.setFontSize(12);
  280.     settingsContainer.addView(settingsDesc);
  281.    
  282.     // 语言设置
  283.     var languageLabel = new Label();
  284.     languageLabel.setText("语言设置");
  285.     languageLabel.setTextColor(60, 60, 60);
  286.     languageLabel.setFontSize(14);
  287.     settingsContainer.addView(languageLabel);
  288.    
  289.     var languageGroup = new RadioButtonGroup();
  290.     languageGroup.setID("language_setting");
  291.     languageGroup.setDefultSelect("简体中文");
  292.    
  293.     // 创建单选按钮并关联到组
  294.     var chineseOption = new RadioButton();
  295.     chineseOption.setText("简体中文");
  296.     chineseOption.setGroup(languageGroup);
  297.    
  298.     var englishOption = new RadioButton();
  299.     englishOption.setText("English");
  300.     englishOption.setGroup(languageGroup);
  301.    
  302.     // 添加单选按钮到容器
  303.     var languageContainer = new Horizontal();
  304.     languageContainer.setSpacing(20);
  305.     languageContainer.setAlignment("center");
  306.     languageContainer.addView(chineseOption);
  307.     languageContainer.addView(englishOption);
  308.     settingsContainer.addView(languageContainer);
  309.    
  310.     // 主题设置
  311.     var themeLabel = new Label();
  312.     themeLabel.setText("主题设置");
  313.     themeLabel.setTextColor(60, 60, 60);
  314.     themeLabel.setFontSize(14);
  315.     settingsContainer.addView(themeLabel);
  316.    
  317.     var themeGroup = new RadioButtonGroup();
  318.     themeGroup.setID("theme_setting");
  319.     themeGroup.setDefultSelect("浅色模式");
  320.    
  321.     // 创建单选按钮并关联到组
  322.     var lightOption = new RadioButton();
  323.     lightOption.setText("浅色模式");
  324.     lightOption.setGroup(themeGroup);
  325.    
  326.     var darkOption = new RadioButton();
  327.     darkOption.setText("深色模式");
  328.     darkOption.setGroup(themeGroup);
  329.    
  330.     // 添加单选按钮到容器
  331.     var themeContainer = new Horizontal();
  332.     themeContainer.setSpacing(20);
  333.     themeContainer.setAlignment("center");
  334.     themeContainer.addView(lightOption);
  335.     themeContainer.addView(darkOption);
  336.     settingsContainer.addView(themeContainer);
  337.    
  338.     var saveSettingsButton = new Button();
  339.     saveSettingsButton.setText("保存设置");
  340.     saveSettingsButton.setColor(46, 139, 87);
  341.     saveSettingsButton.setTextColor(255, 255, 255);
  342.     saveSettingsButton.onClick(function() {
  343.         var langRadio = languageGroup.currentSelectedRadio();
  344.         var themeRadio = themeGroup.currentSelectedRadio();
  345.         var lang = langRadio ? langRadio.getText() : "未选择";
  346.         var theme = themeRadio ? themeRadio.getText() : "未选择";
  347.         printl("保存设置 - 语言: " + lang + ", 主题: " + theme);
  348.         settingsResultLabel.setText("设置已保存: " + lang + ", " + theme);
  349.     });
  350.     settingsContainer.addView(saveSettingsButton);
  351.    
  352.     var settingsResultLabel = new Label();
  353.     settingsResultLabel.setText("等待保存设置...");
  354.     settingsResultLabel.setTextColor(100, 100, 100);
  355.     settingsResultLabel.setFontSize(12);
  356.     settingsContainer.addView(settingsResultLabel);
  357.    
  358.     var settingsGetValueButton = new Button();
  359.     settingsGetValueButton.setText("获取当前值");
  360.     settingsGetValueButton.setColor(70, 130, 180);
  361.     settingsGetValueButton.setTextColor(255, 255, 255);
  362.     settingsGetValueButton.onClick(function() {
  363.         var langRadio = languageGroup.currentSelectedRadio();
  364.         var themeRadio = themeGroup.currentSelectedRadio();
  365.         var lang = langRadio ? langRadio.getText() : "未选择";
  366.         var theme = themeRadio ? themeRadio.getText() : "未选择";
  367.         printl("设置当前值 - 语言: " + lang + ", 主题: " + theme);
  368.         settingsResultLabel.setText("当前值: 语言=" + lang + ", 主题=" + theme);
  369.     });
  370.     settingsContainer.addView(settingsGetValueButton);
  371.    
  372.     advancedPage.addView(settingsContainer);
  373.    
  374.     // 应用2:表单选择
  375.     var appSection2 = new Horizontal();
  376.     appSection2.setAlignment("center");
  377.     appSection2.setBackgroundColor(220, 220, 225);
  378.    
  379.     var appSection2Label = new Label();
  380.     appSection2Label.setText("应用2:表单数据选择");
  381.     appSection2Label.setTextColor(60, 60, 60);
  382.     appSection2Label.setFontSize(15);
  383.     appSection2.addView(appSection2Label);
  384.    
  385.     advancedPage.addView(appSection2);
  386.    
  387.     var formContainer = new Vertical();
  388.     formContainer.setSpacing(12);
  389.     formContainer.setBackgroundColor(255, 255, 255);
  390.    
  391.     var formDesc = new Label();
  392.     formDesc.setText("使用RadioButtonGroup实现表单中的单选功能");
  393.     formDesc.setTextColor(100, 100, 100);
  394.     formDesc.setFontSize(12);
  395.     formContainer.addView(formDesc);
  396.    
  397.     // 性别选择
  398.     var genderFormLabel = new Label();
  399.     genderFormLabel.setText("性别");
  400.     genderFormLabel.setTextColor(60, 60, 60);
  401.     genderFormLabel.setFontSize(14);
  402.     formContainer.addView(genderFormLabel);
  403.    
  404.     var genderFormGroup = new RadioButtonGroup();
  405.     genderFormGroup.setID("form_gender");
  406.     genderFormGroup.setDefultSelect("保密");
  407.    
  408.     // 创建单选按钮并关联到组
  409.     var maleFormOption = new RadioButton();
  410.     maleFormOption.setText("男");
  411.     maleFormOption.setGroup(genderFormGroup);
  412.    
  413.     var femaleFormOption = new RadioButton();
  414.     femaleFormOption.setText("女");
  415.     femaleFormOption.setGroup(genderFormGroup);
  416.    
  417.     var secretOption = new RadioButton();
  418.     secretOption.setText("保密");
  419.     secretOption.setGroup(genderFormGroup);
  420.    
  421.     // 添加单选按钮到容器
  422.     var genderFormContainer = new Horizontal();
  423.     genderFormContainer.setSpacing(20);
  424.     genderFormContainer.addView(maleFormOption);
  425.     genderFormContainer.addView(femaleFormOption);
  426.     genderFormContainer.addView(secretOption);
  427.     formContainer.addView(genderFormContainer);
  428.    
  429.     // 年龄段选择
  430.     var ageLabel = new Label();
  431.     ageLabel.setText("年龄段");
  432.     ageLabel.setTextColor(60, 60, 60);
  433.     ageLabel.setFontSize(14);
  434.     formContainer.addView(ageLabel);
  435.    
  436.     var ageGroup = new RadioButtonGroup();
  437.     ageGroup.setID("form_age");
  438.     ageGroup.setDefultSelect("18-25岁");
  439.    
  440.     // 创建单选按钮并关联到组
  441.     var age1Option = new RadioButton();
  442.     age1Option.setText("18-25岁");
  443.     age1Option.setGroup(ageGroup);
  444.    
  445.     var age2Option = new RadioButton();
  446.     age2Option.setText("26-35岁");
  447.     age2Option.setGroup(ageGroup);
  448.    
  449.     var age3Option = new RadioButton();
  450.     age3Option.setText("36岁以上");
  451.     age3Option.setGroup(ageGroup);
  452.    
  453.     // 添加单选按钮到容器
  454.     var ageContainer = new Horizontal();
  455.     ageContainer.setSpacing(20);
  456.     ageContainer.addView(age1Option);
  457.     ageContainer.addView(age2Option);
  458.     ageContainer.addView(age3Option);
  459.     formContainer.addView(ageContainer);
  460.    
  461.     var submitFormButton = new Button();
  462.     submitFormButton.setText("提交表单");
  463.     submitFormButton.setColor(70, 130, 180);
  464.     submitFormButton.setTextColor(255, 255, 255);
  465.     submitFormButton.onClick(function() {
  466.         var genderRadio = genderFormGroup.currentSelectedRadio();
  467.         var ageRadio = ageGroup.currentSelectedRadio();
  468.         var gender = genderRadio ? genderRadio.getText() : "未选择";
  469.         var age = ageRadio ? ageRadio.getText() : "未选择";
  470.         printl("提交表单 - 性别: " + gender + ", 年龄段: " + age);
  471.         formResultLabel.setText("表单已提交: " + gender + ", " + age);
  472.     });
  473.     formContainer.addView(submitFormButton);
  474.    
  475.     var formResultLabel = new Label();
  476.     formResultLabel.setText("等待提交表单...");
  477.     formResultLabel.setTextColor(100, 100, 100);
  478.     formResultLabel.setFontSize(12);
  479.     formContainer.addView(formResultLabel);
  480.    
  481.     var formGetValueButton = new Button();
  482.     formGetValueButton.setText("获取当前值");
  483.     formGetValueButton.setColor(70, 130, 180);
  484.     formGetValueButton.setTextColor(255, 255, 255);
  485.     formGetValueButton.onClick(function() {
  486.         var genderRadio = genderFormGroup.currentSelectedRadio();
  487.         var ageRadio = ageGroup.currentSelectedRadio();
  488.         var gender = genderRadio ? genderRadio.getText() : "未选择";
  489.         var age = ageRadio ? ageRadio.getText() : "未选择";
  490.         printl("表单当前值 - 性别: " + gender + ", 年龄段: " + age);
  491.         formResultLabel.setText("当前值: 性别=" + gender + ", 年龄段=" + age);
  492.     });
  493.     formContainer.addView(formGetValueButton);
  494.    
  495.     advancedPage.addView(formContainer);
  496.    
  497.     // ====================== 第三页:动态管理演示 ======================
  498.     var dynamicPage = new Vertical();
  499.     dynamicPage.setSpacing(10);
  500.     dynamicPage.setBackgroundColor(255, 255, 255);
  501.    
  502.     var dynamicDesc = new Label();
  503.     dynamicDesc.setText("展示如何动态创建和管理RadioButtonGroup,以及与其他控件的交互");
  504.     dynamicDesc.setTextColor(100, 100, 100);
  505.     dynamicDesc.setFontSize(12);
  506.     dynamicDesc.setTextAlignment("center");
  507.     dynamicPage.addView(dynamicDesc);
  508.    
  509.     // 动态创建RadioButtonGroup
  510.     var dynamicSection1 = new Horizontal();
  511.     dynamicSection1.setAlignment("center");
  512.     dynamicSection1.setBackgroundColor(220, 220, 225);
  513.    
  514.     var dynamicSection1Label = new Label();
  515.     dynamicSection1Label.setText("动态创建RadioButtonGroup");
  516.     dynamicSection1Label.setTextColor(60, 60, 60);
  517.     dynamicSection1Label.setFontSize(15);
  518.     dynamicSection1.addView(dynamicSection1Label);
  519.    
  520.     dynamicPage.addView(dynamicSection1);
  521.    
  522.     var dynamicCreateContainer = new Vertical();
  523.     dynamicCreateContainer.setSpacing(10);
  524.     dynamicCreateContainer.setBackgroundColor(255, 255, 255);
  525.    
  526.     var dynamicCreateDesc = new Label();
  527.     dynamicCreateDesc.setText("通过代码动态创建RadioButtonGroup并添加到界面");
  528.     dynamicCreateDesc.setTextColor(100, 100, 100);
  529.     dynamicCreateDesc.setFontSize(12);
  530.     dynamicCreateContainer.addView(dynamicCreateDesc);
  531.    
  532.     var dynamicCreateButton = new Button();
  533.     dynamicCreateButton.setText("创建新的单选按钮组");
  534.     dynamicCreateButton.setColor(70, 130, 180);
  535.     dynamicCreateButton.setTextColor(255, 255, 255);
  536.     dynamicCreateButton.onClick(function() {
  537.         var newGroup = new RadioButtonGroup();
  538.         var groupId = "dynamic_group_" + dynamicCreateContainer.getViewCount();
  539.         newGroup.setID(groupId);
  540.         newGroup.setDefultSelect("选项A");
  541.         
  542.         var groupLabel = new Label();
  543.         groupLabel.setText("已创建组: " + groupId);
  544.         groupLabel.setTextColor(0, 128, 0);
  545.         groupLabel.setFontSize(11);
  546.         dynamicCreateContainer.addView(groupLabel);
  547.         
  548.         printl("已创建新的RadioButtonGroup,ID: " + groupId);
  549.     });
  550.     dynamicCreateContainer.addView(dynamicCreateButton);
  551.    
  552.     dynamicPage.addView(dynamicCreateContainer);
  553.    
  554.     // 动态读取配置
  555.     var dynamicSection2 = new Horizontal();
  556.     dynamicSection2.setAlignment("center");
  557.     dynamicSection2.setBackgroundColor(220, 220, 225);
  558.    
  559.     var dynamicSection2Label = new Label();
  560.     dynamicSection2Label.setText("动态读取配置");
  561.     dynamicSection2Label.setTextColor(60, 60, 60);
  562.     dynamicSection2Label.setFontSize(15);
  563.     dynamicSection2.addView(dynamicSection2Label);
  564.    
  565.     dynamicPage.addView(dynamicSection2);
  566.    
  567.     var dynamicConfigContainer = new Vertical();
  568.     dynamicConfigContainer.setSpacing(10);
  569.     dynamicConfigContainer.setBackgroundColor(255, 255, 255);
  570.    
  571.     var dynamicConfigDesc = new Label();
  572.     dynamicConfigDesc.setText("通过config读取RadioButtonGroup的配置值");
  573.     dynamicConfigDesc.setTextColor(100, 100, 100);
  574.     dynamicConfigDesc.setFontSize(12);
  575.     dynamicConfigContainer.addView(dynamicConfigDesc);
  576.    
  577.     var configGroup = new RadioButtonGroup();
  578.     configGroup.setID("config_test_group");
  579.     configGroup.setDefultSelect("配置项1");
  580.    
  581.     // 创建单选按钮并关联到组
  582.     var config1Option = new RadioButton();
  583.     config1Option.setText("配置项1");
  584.     config1Option.setGroup(configGroup);
  585.    
  586.     var config2Option = new RadioButton();
  587.     config2Option.setText("配置项2");
  588.     config2Option.setGroup(configGroup);
  589.    
  590.     // 添加单选按钮到容器
  591.     var configContainer = new Horizontal();
  592.     configContainer.setSpacing(20);
  593.     configContainer.addView(config1Option);
  594.     configContainer.addView(config2Option);
  595.     dynamicConfigContainer.addView(configContainer);
  596.    
  597.     var readConfigButton = new Button();
  598.     readConfigButton.setText("读取配置");
  599.     readConfigButton.setColor(46, 139, 87);
  600.     readConfigButton.setTextColor(255, 255, 255);
  601.     readConfigButton.onClick(function() {
  602.         var selectedRadio = configGroup.currentSelectedRadio();
  603.         var selectedText = selectedRadio ? selectedRadio.getText() : "未选择";
  604.         printl("当前选中值: " + selectedText);
  605.         configResultLabel.setText("配置值: " + selectedText);
  606.     });
  607.     dynamicConfigContainer.addView(readConfigButton);
  608.    
  609.     var configResultLabel = new Label();
  610.     configResultLabel.setText("等待读取配置...");
  611.     configResultLabel.setTextColor(100, 100, 100);
  612.     configResultLabel.setFontSize(12);
  613.     dynamicConfigContainer.addView(configResultLabel);
  614.    
  615.     var configGetValueButton = new Button();
  616.     configGetValueButton.setText("获取当前值");
  617.     configGetValueButton.setColor(70, 130, 180);
  618.     configGetValueButton.setTextColor(255, 255, 255);
  619.     configGetValueButton.onClick(function() {
  620.         var selectedRadio = configGroup.currentSelectedRadio();
  621.         var selectedText = selectedRadio ? selectedRadio.getText() : "未选择";
  622.         printl("配置当前值: " + selectedText);
  623.         configResultLabel.setText("当前值: " + selectedText);
  624.     });
  625.     dynamicConfigContainer.addView(configGetValueButton);
  626.    
  627.     dynamicPage.addView(dynamicConfigContainer);
  628.    
  629.     // ====================== 第四页:综合演示 ======================
  630.     var comprehensivePage = new Vertical();
  631.     comprehensivePage.setSpacing(10);
  632.     comprehensivePage.setBackgroundColor(255, 255, 255);
  633.    
  634.     var comprehensiveDesc = new Label();
  635.     comprehensiveDesc.setText("展示RadioButtonGroup在完整应用场景中的综合使用");
  636.     comprehensiveDesc.setTextColor(100, 100, 100);
  637.     comprehensiveDesc.setFontSize(12);
  638.     comprehensiveDesc.setTextAlignment("center");
  639.     comprehensivePage.addView(comprehensiveDesc);
  640.    
  641.     // 完整的问卷调查示例
  642.     var surveySection = new Horizontal();
  643.     surveySection.setAlignment("center");
  644.     surveySection.setBackgroundColor(220, 220, 225);
  645.    
  646.     var surveySectionLabel = new Label();
  647.     surveySectionLabel.setText("综合应用:用户问卷调查");
  648.     surveySectionLabel.setTextColor(60, 60, 60);
  649.     surveySectionLabel.setFontSize(15);
  650.     surveySection.addView(surveySectionLabel);
  651.    
  652.     comprehensivePage.addView(surveySection);
  653.    
  654.     var surveyContainer = new Vertical();
  655.     surveyContainer.setSpacing(15);
  656.     surveyContainer.setBackgroundColor(255, 255, 255);
  657.    
  658.     var surveyTitle = new Label();
  659.     surveyTitle.setText("用户满意度调查");
  660.     surveyTitle.setTextColor(50, 50, 50);
  661.     surveyTitle.setFontSize(16);
  662.     surveyTitle.setTextAlignment("center");
  663.     surveyContainer.addView(surveyTitle);
  664.    
  665.     // 问题1
  666.     var q1Label = new Label();
  667.     q1Label.setText("1. 您对产品的整体满意度如何?");
  668.     q1Label.setTextColor(60, 60, 60);
  669.     q1Label.setFontSize(14);
  670.     surveyContainer.addView(q1Label);
  671.    
  672.     var q1Group = new RadioButtonGroup();
  673.     q1Group.setID("survey_q1");
  674.     q1Group.setDefultSelect("满意");
  675.    
  676.     // 创建单选按钮并关联到组
  677.     var verySatisfiedOption = new RadioButton();
  678.     verySatisfiedOption.setText("非常满意");
  679.     verySatisfiedOption.setGroup(q1Group);
  680.    
  681.     var satisfiedOption = new RadioButton();
  682.     satisfiedOption.setText("满意");
  683.     satisfiedOption.setGroup(q1Group);
  684.    
  685.     var neutralOption = new RadioButton();
  686.     neutralOption.setText("一般");
  687.     neutralOption.setGroup(q1Group);
  688.    
  689.     var dissatisfiedOption = new RadioButton();
  690.     dissatisfiedOption.setText("不满意");
  691.     dissatisfiedOption.setGroup(q1Group);
  692.    
  693.     // 添加单选按钮到容器
  694.     var q1Container = new Vertical();
  695.     q1Container.setSpacing(10);
  696.    
  697.     var q1Row1 = new Horizontal();
  698.     q1Row1.setSpacing(15);
  699.     q1Row1.addView(verySatisfiedOption);
  700.     q1Row1.addView(satisfiedOption);
  701.    
  702.     var q1Row2 = new Horizontal();
  703.     q1Row2.setSpacing(15);
  704.     q1Row2.addView(neutralOption);
  705.     q1Row2.addView(dissatisfiedOption);
  706.    
  707.     q1Container.addView(q1Row1);
  708.     q1Container.addView(q1Row2);
  709.     surveyContainer.addView(q1Container);
  710.    
  711.     // 问题2
  712.     var q2Label = new Label();
  713.     q2Label.setText("2. 您使用产品的频率是?");
  714.     q2Label.setTextColor(60, 60, 60);
  715.     q2Label.setFontSize(14);
  716.     surveyContainer.addView(q2Label);
  717.    
  718.     var q2Group = new RadioButtonGroup();
  719.     q2Group.setID("survey_q2");
  720.     q2Group.setDefultSelect("每天使用");
  721.    
  722.     // 创建单选按钮并关联到组
  723.     var dailyOption = new RadioButton();
  724.     dailyOption.setText("每天使用");
  725.     dailyOption.setGroup(q2Group);
  726.    
  727.     var weeklyOption = new RadioButton();
  728.     weeklyOption.setText("每周使用");
  729.     weeklyOption.setGroup(q2Group);
  730.    
  731.     var monthlyOption = new RadioButton();
  732.     monthlyOption.setText("每月使用");
  733.     monthlyOption.setGroup(q2Group);
  734.    
  735.     var rarelyOption = new RadioButton();
  736.     rarelyOption.setText("很少使用");
  737.     rarelyOption.setGroup(q2Group);
  738.    
  739.     // 添加单选按钮到容器
  740.     var q2Container = new Vertical();
  741.     q2Container.setSpacing(10);
  742.    
  743.     var q2Row1 = new Horizontal();
  744.     q2Row1.setSpacing(15);
  745.     q2Row1.addView(dailyOption);
  746.     q2Row1.addView(weeklyOption);
  747.    
  748.     var q2Row2 = new Horizontal();
  749.     q2Row2.setSpacing(15);
  750.     q2Row2.addView(monthlyOption);
  751.     q2Row2.addView(rarelyOption);
  752.    
  753.     q2Container.addView(q2Row1);
  754.     q2Container.addView(q2Row2);
  755.     surveyContainer.addView(q2Container);
  756.    
  757.     // 问题3
  758.     var q3Label = new Label();
  759.     q3Label.setText("3. 您会推荐给朋友吗?");
  760.     q3Label.setTextColor(60, 60, 60);
  761.     q3Label.setFontSize(14);
  762.     surveyContainer.addView(q3Label);
  763.    
  764.     var q3Group = new RadioButtonGroup();
  765.     q3Group.setID("survey_q3");
  766.     q3Group.setDefultSelect("会推荐");
  767.    
  768.     // 创建单选按钮并关联到组
  769.     var definitelyOption = new RadioButton();
  770.     definitelyOption.setText("肯定会");
  771.     definitelyOption.setGroup(q3Group);
  772.    
  773.     var yesOption = new RadioButton();
  774.     yesOption.setText("会推荐");
  775.     yesOption.setGroup(q3Group);
  776.    
  777.     var maybeOption = new RadioButton();
  778.     maybeOption.setText("可能会");
  779.     maybeOption.setGroup(q3Group);
  780.    
  781.     var noOption = new RadioButton();
  782.     noOption.setText("不会");
  783.     noOption.setGroup(q3Group);
  784.    
  785.     // 添加单选按钮到容器
  786.     var q3Container = new Vertical();
  787.     q3Container.setSpacing(10);
  788.    
  789.     var q3Row1 = new Horizontal();
  790.     q3Row1.setSpacing(15);
  791.     q3Row1.addView(definitelyOption);
  792.     q3Row1.addView(yesOption);
  793.    
  794.     var q3Row2 = new Horizontal();
  795.     q3Row2.setSpacing(15);
  796.     q3Row2.addView(maybeOption);
  797.     q3Row2.addView(noOption);
  798.    
  799.     q3Container.addView(q3Row1);
  800.     q3Container.addView(q3Row2);
  801.     surveyContainer.addView(q3Container);
  802.    
  803.     // 提交按钮
  804.     var submitSurveyButton = new Button();
  805.     submitSurveyButton.setText("提交调查");
  806.     submitSurveyButton.setColor(70, 130, 180);
  807.     submitSurveyButton.setTextColor(255, 255, 255);
  808.     submitSurveyButton.setWidth(150);
  809.     submitSurveyButton.setHeight(45);
  810.     submitSurveyButton.onClick(function() {
  811.         var q1Radio = q1Group.currentSelectedRadio();
  812.         var q2Radio = q2Group.currentSelectedRadio();
  813.         var q3Radio = q3Group.currentSelectedRadio();
  814.         
  815.         var q1Answer = q1Radio ? q1Radio.getText() : "未选择";
  816.         var q2Answer = q2Radio ? q2Radio.getText() : "未选择";
  817.         var q3Answer = q3Radio ? q3Radio.getText() : "未选择";
  818.         
  819.         var result = "调查结果:\n" +
  820.                      "1. 满意度: " + q1Answer + "\n" +
  821.                      "2. 使用频率: " + q2Answer + "\n" +
  822.                      "3. 推荐意愿: " + q3Answer;
  823.         
  824.         printl(result);
  825.         surveyResultLabel.setText(result);
  826.         showToast("调查提交成功!");
  827.     });
  828.     surveyContainer.addView(submitSurveyButton);
  829.    
  830.     var surveyResultLabel = new Label();
  831.     surveyResultLabel.setText("等待提交调查...");
  832.     surveyResultLabel.setTextColor(100, 100, 100);
  833.     surveyResultLabel.setFontSize(12);
  834.     surveyContainer.addView(surveyResultLabel);
  835.    
  836.     var surveyGetValueButton = new Button();
  837.     surveyGetValueButton.setText("获取当前值");
  838.     surveyGetValueButton.setColor(70, 130, 180);
  839.     surveyGetValueButton.setTextColor(255, 255, 255);
  840.     surveyGetValueButton.onClick(function() {
  841.         var q1Radio = q1Group.currentSelectedRadio();
  842.         var q2Radio = q2Group.currentSelectedRadio();
  843.         var q3Radio = q3Group.currentSelectedRadio();
  844.         
  845.         var q1Answer = q1Radio ? q1Radio.getText() : "未选择";
  846.         var q2Answer = q2Radio ? q2Radio.getText() : "未选择";
  847.         var q3Answer = q3Radio ? q3Radio.getText() : "未选择";
  848.         
  849.         var result = "当前值:\n" +
  850.                      "1. 满意度: " + q1Answer + "\n" +
  851.                      "2. 使用频率: " + q2Answer + "\n" +
  852.                      "3. 推荐意愿: " + q3Answer;
  853.         
  854.         printl(result);
  855.         surveyResultLabel.setText(result);
  856.     });
  857.     surveyContainer.addView(surveyGetValueButton);
  858.    
  859.     comprehensivePage.addView(surveyContainer);
  860.    
  861.     // 方法总结
  862.     var summarySection = new Horizontal();
  863.     summarySection.setAlignment("center");
  864.     summarySection.setBackgroundColor(220, 220, 225);
  865.    
  866.     var summarySectionLabel = new Label();
  867.     summarySectionLabel.setText("方法总结");
  868.     summarySectionLabel.setTextColor(60, 60, 60);
  869.     summarySectionLabel.setFontSize(15);
  870.     summarySection.addView(summarySectionLabel);
  871.    
  872.     comprehensivePage.addView(summarySection);
  873.    
  874.     var summaryContainer = new Vertical();
  875.     summaryContainer.setSpacing(10);
  876.     summaryContainer.setBackgroundColor(255, 255, 255);
  877.    
  878.     var summaryLabel = new Label();
  879.     summaryLabel.setText("RadioButtonGroup核心方法总结:\n\n" +
  880.                         "1. setID(id) - 设置控件唯一标识符\n" +
  881.                         "   用途:为单选按钮组设置ID,便于通过config读取配置\n" +
  882.                         "   示例:rg.setID(\"abc\")\n\n" +
  883.                         "2. setDefultSelect(value) - 设置默认选中项\n" +
  884.                         "   用途:初始化时自动选中指定的选项\n" +
  885.                         "   示例:rg.setDefultSelect(\"男\")\n\n" +
  886.                         "3. currentSelectedRadio() - 获取当前选中项\n" +
  887.                         "   用途:获取用户当前选择的选项\n" +
  888.                         "   示例:rg.currentSelectedRadio()");
  889.     summaryLabel.setTextColor(60, 60, 60);
  890.     summaryLabel.setFontSize(11);
  891.     summaryLabel.setBackgroundColor(245, 245, 255);
  892.     summaryContainer.addView(summaryLabel);
  893.    
  894.     comprehensivePage.addView(summaryContainer);
  895.    
  896.     // ====================== 第五页:返回桌面 ======================
  897.     var returnPage = new Vertical();
  898.     returnPage.setSpacing(30);
  899.     returnPage.setBackgroundColor(245, 248, 250);
  900.     returnPage.setAlignment("center");
  901.    
  902.     var returnHeader = new Horizontal();
  903.     returnHeader.setAlignment("center");
  904.     returnHeader.setBackgroundColor(70, 130, 180);
  905.    
  906.     var returnHeaderLabel = new Label();
  907.     returnHeaderLabel.setText("返回桌面");
  908.     returnHeaderLabel.setTextColor(255, 255, 255);
  909.     returnHeaderLabel.setFontSize(20);
  910.     returnHeader.addView(returnHeaderLabel);
  911.    
  912.     returnPage.addView(returnHeader);
  913.    
  914.     var returnDesc = new Label();
  915.     returnDesc.setText("点击下方按钮返回桌面");
  916.     returnDesc.setTextColor(100, 100, 100);
  917.     returnDesc.setFontSize(16);
  918.     returnDesc.setTextAlignment("center");
  919.     returnPage.addView(returnDesc);
  920.    
  921.     var returnButton = new Button();
  922.     returnButton.setText("返回桌面");
  923.     returnButton.setColor(255, 99, 71); // 番茄红色背景
  924.     returnButton.setTextColor(255, 255, 255); // 白色文字
  925.     returnButton.setWidth(180);
  926.     returnButton.setHeight(50);
  927.     returnButton.onClick(function() {
  928.         printl("返回桌面按钮被点击");
  929.         tab.dismiss();
  930.         showToast("已返回桌面");
  931.     });
  932.     returnPage.addView(returnButton);
  933.    
  934.     // ====================== 添加所有页面到TabView ======================
  935.     tab.addView(0, basicPage);
  936.     tab.addView(1, advancedPage);
  937.     tab.addView(2, dynamicPage);
  938.     tab.addView(3, comprehensivePage);
  939.     tab.addView(4, returnPage);
  940.    
  941.     printl("RadioButtonGroup示例视图添加完成");
  942. });

  943. // 显示提示信息函数
  944. function showToast(message) {
  945.     printl("提示: " + message);
  946. }

  947. // 日志输出函数
  948. function printl(message) {
  949.     console.log("[RadioButtonGroup Example] " + message);
  950. }

  951. // 代码说明:
  952. // 1. 本示例全面展示了RadioButtonGroup的三个核心方法:setID、setDefultSelect、currentSelectedRadio
  953. // 2. 第一页展示了基础方法的单独使用和代码示例
  954. // 3. 第二页展示了RadioButtonGroup在实际应用场景中的使用,如用户设置、表单选择等
  955. // 4. 第三页展示了动态创建和管理RadioButtonGroup的方法
  956. // 5. 第四页展示了综合应用场景,包括完整的问卷调查示例
  957. // 6. 代码遵循AIWROK平台的方法规范,使用ES5语法
  958. // 7. 所有示例都包含详细的注释和说明
  959. // 8. 可以根据实际需求修改和扩展功能
复制代码












欢迎光临 自动发帖软件 (http://www.fatiegongju.com/) Powered by Discuz! X3.2