|
|
Æ»¹ûAIWROKʵÀýµ¥Ñ¡°´Å¥×éÀà[RadioButtonGroup]ÍêÕû×ÛºÏʾÀý
- // 🎨UI-µ¥Ñ¡°´Å¥×éÀà[RadioButtonGroup]ÍêÕû×ÛºÏʾÀý
- // È«ÃæÕ¹Ê¾RadioButtonGroupµÄËùÓй¦Äܺͷ½·¨
- // 🍎½»Á÷QQȺ711841924Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639
- printl("=== RadioButtonGroupµ¥Ñ¡°´Å¥×éÍêÕû×ÛºÏʾÀýÆô¶¯ ===");
- var tab = new TabView();
- tab.setTitles(["»ù´¡", "¸ß¼¶", "¶¯Ì¬", "×ÛºÏ", "·µ»Ø"]);
- tab.show(function() {
- printl("TabView½çÃæ¼ÓÔØÍê³É");
-
- // ====================== µÚÒ»Ò³£º»ù´¡·½·¨ÑÝʾ ======================
- var basicPage = new Vertical();
- basicPage.setSpacing(10);
- basicPage.setBackgroundColor(255, 255, 255);
-
- var basicDesc = new Label();
- basicDesc.setText("չʾRadioButtonGroupµÄÈý¸öºËÐÄ·½·¨£ºsetID¡¢setDefultSelect¡¢currentSelectedRadio");
- basicDesc.setTextColor(100, 100, 100);
- basicDesc.setFontSize(12);
- basicDesc.setTextAlignment("center");
- basicPage.addView(basicDesc);
-
- // ·½·¨1£ºsetIDÉèÖÿؼþID
- var section1 = new Horizontal();
- section1.setAlignment("center");
- section1.setBackgroundColor(220, 220, 225);
-
- var section1Label = new Label();
- section1Label.setText("·½·¨1£ºsetIDÉèÖÿؼþID");
- section1Label.setTextColor(60, 60, 60);
- section1Label.setFontSize(15);
- section1.addView(section1Label);
-
- basicPage.addView(section1);
-
- var idDemoContainer = new Vertical();
- idDemoContainer.setSpacing(10);
- idDemoContainer.setBackgroundColor(255, 255, 255);
-
- var idDesc = new Label();
- idDesc.setText("Ϊµ¥Ñ¡°´Å¥×éÉèÖÃΨһ±êʶ·û£¬·½±ãºóÐøÍ¨¹ýconfig¶ÁÈ¡ÅäÖÃ");
- idDesc.setTextColor(100, 100, 100);
- idDesc.setFontSize(12);
- idDemoContainer.addView(idDesc);
-
- var idCodeLabel = new Label();
- idCodeLabel.setText("var rg = new RadioButtonGroup();\nrg.setID(\"abc\");\n// ¶ÁȡʹÓÃ\nconfig.getConfig(\"abc\");");
- idCodeLabel.setTextColor(50, 50, 150);
- idCodeLabel.setFontSize(11);
- idCodeLabel.setBackgroundColor(245, 245, 255);
- idDemoContainer.addView(idCodeLabel);
-
- var idDemoGroup = new RadioButtonGroup();
- idDemoGroup.setID("demo_group_1");
- idDemoGroup.setDefultSelect("Ñ¡ÏîA");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var optionA = new RadioButton();
- optionA.setText("Ñ¡ÏîA");
- optionA.setGroup(idDemoGroup);
-
- var optionB = new RadioButton();
- optionB.setText("Ñ¡ÏîB");
- optionB.setGroup(idDemoGroup);
-
- var optionC = new RadioButton();
- optionC.setText("Ñ¡ÏîC");
- optionC.setGroup(idDemoGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var radioContainer = new Horizontal();
- radioContainer.setSpacing(20);
- radioContainer.addView(optionA);
- radioContainer.addView(optionB);
- radioContainer.addView(optionC);
- idDemoContainer.addView(radioContainer);
-
- var idResultLabel = new Label();
- idResultLabel.setText("¿Ø¼þIDÒÑÉèÖÃΪ£ºdemo_group_1");
- idResultLabel.setTextColor(0, 128, 0);
- idResultLabel.setFontSize(12);
- idDemoContainer.addView(idResultLabel);
-
- var idGetValueButton = new Button();
- idGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- idGetValueButton.setColor(70, 130, 180);
- idGetValueButton.setTextColor(255, 255, 255);
- idGetValueButton.onClick(function() {
- var selected = idDemoGroup.currentSelectedRadio();
- var selectedText = selected ? selected.getText() : "δѡÔñ";
- printl("·½·¨1µ±Ç°Ñ¡ÖÐÏî: " + selectedText);
- idResultLabel.setText("¿Ø¼þIDÒÑÉèÖÃΪ£ºdemo_group_1£¬µ±Ç°Ñ¡ÖÐ: " + selectedText);
- });
- idDemoContainer.addView(idGetValueButton);
-
- basicPage.addView(idDemoContainer);
-
- // ·½·¨2£ºsetDefultSelectÉèÖÃĬÈÏÖµ
- var section2 = new Horizontal();
- section2.setAlignment("center");
- section2.setBackgroundColor(220, 220, 225);
-
- var section2Label = new Label();
- section2Label.setText("·½·¨2£ºsetDefultSelectÉèÖÃĬÈÏÖµ");
- section2Label.setTextColor(60, 60, 60);
- section2Label.setFontSize(15);
- section2.addView(section2Label);
-
- basicPage.addView(section2);
-
- var defaultDemoContainer = new Vertical();
- defaultDemoContainer.setSpacing(10);
- defaultDemoContainer.setBackgroundColor(255, 255, 255);
-
- var defaultDesc = new Label();
- defaultDesc.setText("ÉèÖõ¥Ñ¡°´Å¥×éµÄĬÈÏÑ¡ÖÐÏ³õʼ»¯Ê±×Ô¶¯Ñ¡ÖÐÖ¸¶¨Ñ¡Ïî");
- defaultDesc.setTextColor(100, 100, 100);
- defaultDesc.setFontSize(12);
- defaultDemoContainer.addView(defaultDesc);
-
- var defaultCodeLabel = new Label();
- defaultCodeLabel.setText("var rg = new RadioButtonGroup();\nrg.setID(\"ÐÔ±ð\")\nrg.setDefultSelect(\"ÄÐ\");");
- defaultCodeLabel.setTextColor(50, 50, 150);
- defaultCodeLabel.setFontSize(11);
- defaultCodeLabel.setBackgroundColor(245, 245, 255);
- defaultDemoContainer.addView(defaultCodeLabel);
-
- var genderGroup = new RadioButtonGroup();
- genderGroup.setID("gender_group");
- genderGroup.setDefultSelect("ÄÐ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var maleOption = new RadioButton();
- maleOption.setText("ÄÐ");
- maleOption.setGroup(genderGroup);
-
- var femaleOption = new RadioButton();
- femaleOption.setText("Å®");
- femaleOption.setGroup(genderGroup);
-
- var otherOption = new RadioButton();
- otherOption.setText("ÆäËû");
- otherOption.setGroup(genderGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var genderContainer = new Horizontal();
- genderContainer.setSpacing(20);
- genderContainer.addView(maleOption);
- genderContainer.addView(femaleOption);
- genderContainer.addView(otherOption);
- defaultDemoContainer.addView(genderContainer);
-
- var defaultResultLabel = new Label();
- defaultResultLabel.setText("ĬÈÏÑ¡ÖÐÏÄÐ");
- defaultResultLabel.setTextColor(0, 128, 0);
- defaultResultLabel.setFontSize(12);
- defaultDemoContainer.addView(defaultResultLabel);
-
- var defaultGetValueButton = new Button();
- defaultGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- defaultGetValueButton.setColor(70, 130, 180);
- defaultGetValueButton.setTextColor(255, 255, 255);
- defaultGetValueButton.onClick(function() {
- var selected = genderGroup.currentSelectedRadio();
- var selectedText = selected ? selected.getText() : "δѡÔñ";
- printl("·½·¨2µ±Ç°Ñ¡ÖÐÏî: " + selectedText);
- defaultResultLabel.setText("ĬÈÏÑ¡ÖÐÏÄУ¬µ±Ç°Ñ¡ÖÐ: " + selectedText);
- });
- defaultDemoContainer.addView(defaultGetValueButton);
-
- basicPage.addView(defaultDemoContainer);
-
- // ·½·¨3£ºcurrentSelectedRadioµ±Ç°Ñ¡Öеĵ¥Ñ¡°´Å¥
- var section3 = new Horizontal();
- section3.setAlignment("center");
- section3.setBackgroundColor(220, 220, 225);
-
- var section3Label = new Label();
- section3Label.setText("·½·¨3£ºcurrentSelectedRadio»ñÈ¡µ±Ç°Ñ¡ÖÐÏî");
- section3Label.setTextColor(60, 60, 60);
- section3Label.setFontSize(15);
- section3.addView(section3Label);
-
- basicPage.addView(section3);
-
- var currentDemoContainer = new Vertical();
- currentDemoContainer.setSpacing(10);
- currentDemoContainer.setBackgroundColor(255, 255, 255);
-
- var currentDesc = new Label();
- currentDesc.setText("»ñÈ¡µ±Ç°Ñ¡Öеĵ¥Ñ¡°´Å¥£¬ÓÃÓÚ¶ÁÈ¡Óû§Ñ¡Ôñ»ò½øÐкóÐø²Ù×÷");
- currentDesc.setTextColor(100, 100, 100);
- currentDesc.setFontSize(12);
- currentDemoContainer.addView(currentDesc);
-
- var currentCodeLabel = new Label();
- currentCodeLabel.setText("new RadioButtonGroup().currentSelectedRadio()");
- currentCodeLabel.setTextColor(50, 50, 150);
- currentCodeLabel.setFontSize(11);
- currentCodeLabel.setBackgroundColor(245, 245, 255);
- currentDemoContainer.addView(currentCodeLabel);
-
- var currentGroup = new RadioButtonGroup();
- currentGroup.setID("current_group");
- currentGroup.setDefultSelect("Ñ¡Ïî1");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var option1 = new RadioButton();
- option1.setText("Ñ¡Ïî1");
- option1.setGroup(currentGroup);
-
- var option2 = new RadioButton();
- option2.setText("Ñ¡Ïî2");
- option2.setGroup(currentGroup);
-
- var option3 = new RadioButton();
- option3.setText("Ñ¡Ïî3");
- option3.setGroup(currentGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var currentRadioContainer = new Horizontal();
- currentRadioContainer.setSpacing(20);
- currentRadioContainer.addView(option1);
- currentRadioContainer.addView(option2);
- currentRadioContainer.addView(option3);
- currentDemoContainer.addView(currentRadioContainer);
-
- var currentButton = new Button();
- currentButton.setText("»ñÈ¡µ±Ç°Ñ¡ÖÐÏî");
- currentButton.setColor(70, 130, 180);
- currentButton.setTextColor(255, 255, 255);
- currentButton.onClick(function() {
- var selected = currentGroup.currentSelectedRadio();
- var selectedText = selected ? selected.getText() : "δѡÔñ";
- printl("µ±Ç°Ñ¡ÖÐÏî: " + selectedText);
- currentResultLabel.setText("µ±Ç°Ñ¡ÖÐÏî: " + selectedText);
- });
- currentDemoContainer.addView(currentButton);
-
- var currentResultLabel = new Label();
- currentResultLabel.setText("µ±Ç°Ñ¡ÖÐÏѡÏî1");
- currentResultLabel.setTextColor(0, 128, 0);
- currentResultLabel.setFontSize(12);
- currentDemoContainer.addView(currentResultLabel);
-
- basicPage.addView(currentDemoContainer);
-
- // ====================== µÚ¶þÒ³£º¸ß¼¶Ó¦ÓÃÑÝʾ ======================
- var advancedPage = new Vertical();
- advancedPage.setSpacing(10);
- advancedPage.setBackgroundColor(255, 255, 255);
-
- var advancedDesc = new Label();
- advancedDesc.setText("չʾRadioButtonGroupÔÚʵ¼ÊÓ¦Óó¡¾°ÖеÄʹÓ÷½·¨");
- advancedDesc.setTextColor(100, 100, 100);
- advancedDesc.setFontSize(12);
- advancedDesc.setTextAlignment("center");
- advancedPage.addView(advancedDesc);
-
- // Ó¦ÓÃ1£ºÓû§ÉèÖýçÃæ
- var appSection1 = new Horizontal();
- appSection1.setAlignment("center");
- appSection1.setBackgroundColor(220, 220, 225);
-
- var appSection1Label = new Label();
- appSection1Label.setText("Ó¦ÓÃ1£ºÓû§ÉèÖýçÃæ");
- appSection1Label.setTextColor(60, 60, 60);
- appSection1Label.setFontSize(15);
- appSection1.addView(appSection1Label);
-
- advancedPage.addView(appSection1);
-
- var settingsContainer = new Vertical();
- settingsContainer.setSpacing(12);
- settingsContainer.setBackgroundColor(255, 255, 255);
-
- var settingsDesc = new Label();
- settingsDesc.setText("ʹÓÃRadioButtonGroupʵÏÖÓû§Æ«ºÃÉèÖÃ");
- settingsDesc.setTextColor(100, 100, 100);
- settingsDesc.setFontSize(12);
- settingsContainer.addView(settingsDesc);
-
- // ÓïÑÔÉèÖÃ
- var languageLabel = new Label();
- languageLabel.setText("ÓïÑÔÉèÖÃ");
- languageLabel.setTextColor(60, 60, 60);
- languageLabel.setFontSize(14);
- settingsContainer.addView(languageLabel);
-
- var languageGroup = new RadioButtonGroup();
- languageGroup.setID("language_setting");
- languageGroup.setDefultSelect("¼òÌåÖÐÎÄ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var chineseOption = new RadioButton();
- chineseOption.setText("¼òÌåÖÐÎÄ");
- chineseOption.setGroup(languageGroup);
-
- var englishOption = new RadioButton();
- englishOption.setText("English");
- englishOption.setGroup(languageGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var languageContainer = new Horizontal();
- languageContainer.setSpacing(20);
- languageContainer.setAlignment("center");
- languageContainer.addView(chineseOption);
- languageContainer.addView(englishOption);
- settingsContainer.addView(languageContainer);
-
- // Ö÷ÌâÉèÖÃ
- var themeLabel = new Label();
- themeLabel.setText("Ö÷ÌâÉèÖÃ");
- themeLabel.setTextColor(60, 60, 60);
- themeLabel.setFontSize(14);
- settingsContainer.addView(themeLabel);
-
- var themeGroup = new RadioButtonGroup();
- themeGroup.setID("theme_setting");
- themeGroup.setDefultSelect("dzɫģʽ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var lightOption = new RadioButton();
- lightOption.setText("dzɫģʽ");
- lightOption.setGroup(themeGroup);
-
- var darkOption = new RadioButton();
- darkOption.setText("Éîɫģʽ");
- darkOption.setGroup(themeGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var themeContainer = new Horizontal();
- themeContainer.setSpacing(20);
- themeContainer.setAlignment("center");
- themeContainer.addView(lightOption);
- themeContainer.addView(darkOption);
- settingsContainer.addView(themeContainer);
-
- var saveSettingsButton = new Button();
- saveSettingsButton.setText("±£´æÉèÖÃ");
- saveSettingsButton.setColor(46, 139, 87);
- saveSettingsButton.setTextColor(255, 255, 255);
- saveSettingsButton.onClick(function() {
- var langRadio = languageGroup.currentSelectedRadio();
- var themeRadio = themeGroup.currentSelectedRadio();
- var lang = langRadio ? langRadio.getText() : "δѡÔñ";
- var theme = themeRadio ? themeRadio.getText() : "δѡÔñ";
- printl("±£´æÉèÖà - ÓïÑÔ: " + lang + ", Ö÷Ìâ: " + theme);
- settingsResultLabel.setText("ÉèÖÃÒѱ£´æ: " + lang + ", " + theme);
- });
- settingsContainer.addView(saveSettingsButton);
-
- var settingsResultLabel = new Label();
- settingsResultLabel.setText("µÈ´ý±£´æÉèÖÃ...");
- settingsResultLabel.setTextColor(100, 100, 100);
- settingsResultLabel.setFontSize(12);
- settingsContainer.addView(settingsResultLabel);
-
- var settingsGetValueButton = new Button();
- settingsGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- settingsGetValueButton.setColor(70, 130, 180);
- settingsGetValueButton.setTextColor(255, 255, 255);
- settingsGetValueButton.onClick(function() {
- var langRadio = languageGroup.currentSelectedRadio();
- var themeRadio = themeGroup.currentSelectedRadio();
- var lang = langRadio ? langRadio.getText() : "δѡÔñ";
- var theme = themeRadio ? themeRadio.getText() : "δѡÔñ";
- printl("ÉèÖõ±Ç°Öµ - ÓïÑÔ: " + lang + ", Ö÷Ìâ: " + theme);
- settingsResultLabel.setText("µ±Ç°Öµ: ÓïÑÔ=" + lang + ", Ö÷Ìâ=" + theme);
- });
- settingsContainer.addView(settingsGetValueButton);
-
- advancedPage.addView(settingsContainer);
-
- // Ó¦ÓÃ2£º±íµ¥Ñ¡Ôñ
- var appSection2 = new Horizontal();
- appSection2.setAlignment("center");
- appSection2.setBackgroundColor(220, 220, 225);
-
- var appSection2Label = new Label();
- appSection2Label.setText("Ó¦ÓÃ2£º±íµ¥Êý¾ÝÑ¡Ôñ");
- appSection2Label.setTextColor(60, 60, 60);
- appSection2Label.setFontSize(15);
- appSection2.addView(appSection2Label);
-
- advancedPage.addView(appSection2);
-
- var formContainer = new Vertical();
- formContainer.setSpacing(12);
- formContainer.setBackgroundColor(255, 255, 255);
-
- var formDesc = new Label();
- formDesc.setText("ʹÓÃRadioButtonGroupʵÏÖ±íµ¥Öеĵ¥Ñ¡¹¦ÄÜ");
- formDesc.setTextColor(100, 100, 100);
- formDesc.setFontSize(12);
- formContainer.addView(formDesc);
-
- // ÐÔ±ðÑ¡Ôñ
- var genderFormLabel = new Label();
- genderFormLabel.setText("ÐÔ±ð");
- genderFormLabel.setTextColor(60, 60, 60);
- genderFormLabel.setFontSize(14);
- formContainer.addView(genderFormLabel);
-
- var genderFormGroup = new RadioButtonGroup();
- genderFormGroup.setID("form_gender");
- genderFormGroup.setDefultSelect("±£ÃÜ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var maleFormOption = new RadioButton();
- maleFormOption.setText("ÄÐ");
- maleFormOption.setGroup(genderFormGroup);
-
- var femaleFormOption = new RadioButton();
- femaleFormOption.setText("Å®");
- femaleFormOption.setGroup(genderFormGroup);
-
- var secretOption = new RadioButton();
- secretOption.setText("±£ÃÜ");
- secretOption.setGroup(genderFormGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var genderFormContainer = new Horizontal();
- genderFormContainer.setSpacing(20);
- genderFormContainer.addView(maleFormOption);
- genderFormContainer.addView(femaleFormOption);
- genderFormContainer.addView(secretOption);
- formContainer.addView(genderFormContainer);
-
- // ÄêÁä¶ÎÑ¡Ôñ
- var ageLabel = new Label();
- ageLabel.setText("ÄêÁä¶Î");
- ageLabel.setTextColor(60, 60, 60);
- ageLabel.setFontSize(14);
- formContainer.addView(ageLabel);
-
- var ageGroup = new RadioButtonGroup();
- ageGroup.setID("form_age");
- ageGroup.setDefultSelect("18-25Ëê");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var age1Option = new RadioButton();
- age1Option.setText("18-25Ëê");
- age1Option.setGroup(ageGroup);
-
- var age2Option = new RadioButton();
- age2Option.setText("26-35Ëê");
- age2Option.setGroup(ageGroup);
-
- var age3Option = new RadioButton();
- age3Option.setText("36ËêÒÔÉÏ");
- age3Option.setGroup(ageGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var ageContainer = new Horizontal();
- ageContainer.setSpacing(20);
- ageContainer.addView(age1Option);
- ageContainer.addView(age2Option);
- ageContainer.addView(age3Option);
- formContainer.addView(ageContainer);
-
- var submitFormButton = new Button();
- submitFormButton.setText("Ìá½»±íµ¥");
- submitFormButton.setColor(70, 130, 180);
- submitFormButton.setTextColor(255, 255, 255);
- submitFormButton.onClick(function() {
- var genderRadio = genderFormGroup.currentSelectedRadio();
- var ageRadio = ageGroup.currentSelectedRadio();
- var gender = genderRadio ? genderRadio.getText() : "δѡÔñ";
- var age = ageRadio ? ageRadio.getText() : "δѡÔñ";
- printl("Ìá½»±íµ¥ - ÐÔ±ð: " + gender + ", ÄêÁä¶Î: " + age);
- formResultLabel.setText("±íµ¥ÒÑÌá½»: " + gender + ", " + age);
- });
- formContainer.addView(submitFormButton);
-
- var formResultLabel = new Label();
- formResultLabel.setText("µÈ´ýÌá½»±íµ¥...");
- formResultLabel.setTextColor(100, 100, 100);
- formResultLabel.setFontSize(12);
- formContainer.addView(formResultLabel);
-
- var formGetValueButton = new Button();
- formGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- formGetValueButton.setColor(70, 130, 180);
- formGetValueButton.setTextColor(255, 255, 255);
- formGetValueButton.onClick(function() {
- var genderRadio = genderFormGroup.currentSelectedRadio();
- var ageRadio = ageGroup.currentSelectedRadio();
- var gender = genderRadio ? genderRadio.getText() : "δѡÔñ";
- var age = ageRadio ? ageRadio.getText() : "δѡÔñ";
- printl("±íµ¥µ±Ç°Öµ - ÐÔ±ð: " + gender + ", ÄêÁä¶Î: " + age);
- formResultLabel.setText("µ±Ç°Öµ: ÐÔ±ð=" + gender + ", ÄêÁä¶Î=" + age);
- });
- formContainer.addView(formGetValueButton);
-
- advancedPage.addView(formContainer);
-
- // ====================== µÚÈýÒ³£º¶¯Ì¬¹ÜÀíÑÝʾ ======================
- var dynamicPage = new Vertical();
- dynamicPage.setSpacing(10);
- dynamicPage.setBackgroundColor(255, 255, 255);
-
- var dynamicDesc = new Label();
- dynamicDesc.setText("չʾÈçºÎ¶¯Ì¬´´½¨ºÍ¹ÜÀíRadioButtonGroup£¬ÒÔ¼°ÓëÆäËû¿Ø¼þµÄ½»»¥");
- dynamicDesc.setTextColor(100, 100, 100);
- dynamicDesc.setFontSize(12);
- dynamicDesc.setTextAlignment("center");
- dynamicPage.addView(dynamicDesc);
-
- // ¶¯Ì¬´´½¨RadioButtonGroup
- var dynamicSection1 = new Horizontal();
- dynamicSection1.setAlignment("center");
- dynamicSection1.setBackgroundColor(220, 220, 225);
-
- var dynamicSection1Label = new Label();
- dynamicSection1Label.setText("¶¯Ì¬´´½¨RadioButtonGroup");
- dynamicSection1Label.setTextColor(60, 60, 60);
- dynamicSection1Label.setFontSize(15);
- dynamicSection1.addView(dynamicSection1Label);
-
- dynamicPage.addView(dynamicSection1);
-
- var dynamicCreateContainer = new Vertical();
- dynamicCreateContainer.setSpacing(10);
- dynamicCreateContainer.setBackgroundColor(255, 255, 255);
-
- var dynamicCreateDesc = new Label();
- dynamicCreateDesc.setText("ͨ¹ý´úÂ붯̬´´½¨RadioButtonGroup²¢Ìí¼Óµ½½çÃæ");
- dynamicCreateDesc.setTextColor(100, 100, 100);
- dynamicCreateDesc.setFontSize(12);
- dynamicCreateContainer.addView(dynamicCreateDesc);
-
- var dynamicCreateButton = new Button();
- dynamicCreateButton.setText("´´½¨Ðµĵ¥Ñ¡°´Å¥×é");
- dynamicCreateButton.setColor(70, 130, 180);
- dynamicCreateButton.setTextColor(255, 255, 255);
- dynamicCreateButton.onClick(function() {
- var newGroup = new RadioButtonGroup();
- var groupId = "dynamic_group_" + dynamicCreateContainer.getViewCount();
- newGroup.setID(groupId);
- newGroup.setDefultSelect("Ñ¡ÏîA");
-
- var groupLabel = new Label();
- groupLabel.setText("ÒÑ´´½¨×é: " + groupId);
- groupLabel.setTextColor(0, 128, 0);
- groupLabel.setFontSize(11);
- dynamicCreateContainer.addView(groupLabel);
-
- printl("ÒÑ´´½¨ÐµÄRadioButtonGroup£¬ID: " + groupId);
- });
- dynamicCreateContainer.addView(dynamicCreateButton);
-
- dynamicPage.addView(dynamicCreateContainer);
-
- // ¶¯Ì¬¶ÁÈ¡ÅäÖÃ
- var dynamicSection2 = new Horizontal();
- dynamicSection2.setAlignment("center");
- dynamicSection2.setBackgroundColor(220, 220, 225);
-
- var dynamicSection2Label = new Label();
- dynamicSection2Label.setText("¶¯Ì¬¶ÁÈ¡ÅäÖÃ");
- dynamicSection2Label.setTextColor(60, 60, 60);
- dynamicSection2Label.setFontSize(15);
- dynamicSection2.addView(dynamicSection2Label);
-
- dynamicPage.addView(dynamicSection2);
-
- var dynamicConfigContainer = new Vertical();
- dynamicConfigContainer.setSpacing(10);
- dynamicConfigContainer.setBackgroundColor(255, 255, 255);
-
- var dynamicConfigDesc = new Label();
- dynamicConfigDesc.setText("ͨ¹ýconfig¶ÁÈ¡RadioButtonGroupµÄÅäÖÃÖµ");
- dynamicConfigDesc.setTextColor(100, 100, 100);
- dynamicConfigDesc.setFontSize(12);
- dynamicConfigContainer.addView(dynamicConfigDesc);
-
- var configGroup = new RadioButtonGroup();
- configGroup.setID("config_test_group");
- configGroup.setDefultSelect("ÅäÖÃÏî1");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var config1Option = new RadioButton();
- config1Option.setText("ÅäÖÃÏî1");
- config1Option.setGroup(configGroup);
-
- var config2Option = new RadioButton();
- config2Option.setText("ÅäÖÃÏî2");
- config2Option.setGroup(configGroup);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var configContainer = new Horizontal();
- configContainer.setSpacing(20);
- configContainer.addView(config1Option);
- configContainer.addView(config2Option);
- dynamicConfigContainer.addView(configContainer);
-
- var readConfigButton = new Button();
- readConfigButton.setText("¶ÁÈ¡ÅäÖÃ");
- readConfigButton.setColor(46, 139, 87);
- readConfigButton.setTextColor(255, 255, 255);
- readConfigButton.onClick(function() {
- var selectedRadio = configGroup.currentSelectedRadio();
- var selectedText = selectedRadio ? selectedRadio.getText() : "δѡÔñ";
- printl("µ±Ç°Ñ¡ÖÐÖµ: " + selectedText);
- configResultLabel.setText("ÅäÖÃÖµ: " + selectedText);
- });
- dynamicConfigContainer.addView(readConfigButton);
-
- var configResultLabel = new Label();
- configResultLabel.setText("µÈ´ý¶ÁÈ¡ÅäÖÃ...");
- configResultLabel.setTextColor(100, 100, 100);
- configResultLabel.setFontSize(12);
- dynamicConfigContainer.addView(configResultLabel);
-
- var configGetValueButton = new Button();
- configGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- configGetValueButton.setColor(70, 130, 180);
- configGetValueButton.setTextColor(255, 255, 255);
- configGetValueButton.onClick(function() {
- var selectedRadio = configGroup.currentSelectedRadio();
- var selectedText = selectedRadio ? selectedRadio.getText() : "δѡÔñ";
- printl("ÅäÖõ±Ç°Öµ: " + selectedText);
- configResultLabel.setText("µ±Ç°Öµ: " + selectedText);
- });
- dynamicConfigContainer.addView(configGetValueButton);
-
- dynamicPage.addView(dynamicConfigContainer);
-
- // ====================== µÚËÄÒ³£º×ÛºÏÑÝʾ ======================
- var comprehensivePage = new Vertical();
- comprehensivePage.setSpacing(10);
- comprehensivePage.setBackgroundColor(255, 255, 255);
-
- var comprehensiveDesc = new Label();
- comprehensiveDesc.setText("չʾRadioButtonGroupÔÚÍêÕûÓ¦Óó¡¾°ÖеÄ×ÛºÏʹÓÃ");
- comprehensiveDesc.setTextColor(100, 100, 100);
- comprehensiveDesc.setFontSize(12);
- comprehensiveDesc.setTextAlignment("center");
- comprehensivePage.addView(comprehensiveDesc);
-
- // ÍêÕûµÄÎʾíµ÷²éʾÀý
- var surveySection = new Horizontal();
- surveySection.setAlignment("center");
- surveySection.setBackgroundColor(220, 220, 225);
-
- var surveySectionLabel = new Label();
- surveySectionLabel.setText("×ÛºÏÓ¦ÓãºÓû§Îʾíµ÷²é");
- surveySectionLabel.setTextColor(60, 60, 60);
- surveySectionLabel.setFontSize(15);
- surveySection.addView(surveySectionLabel);
-
- comprehensivePage.addView(surveySection);
-
- var surveyContainer = new Vertical();
- surveyContainer.setSpacing(15);
- surveyContainer.setBackgroundColor(255, 255, 255);
-
- var surveyTitle = new Label();
- surveyTitle.setText("Óû§ÂúÒâ¶Èµ÷²é");
- surveyTitle.setTextColor(50, 50, 50);
- surveyTitle.setFontSize(16);
- surveyTitle.setTextAlignment("center");
- surveyContainer.addView(surveyTitle);
-
- // ÎÊÌâ1
- var q1Label = new Label();
- q1Label.setText("1. Äú¶Ô²úÆ·µÄÕûÌåÂúÒâ¶ÈÈçºÎ£¿");
- q1Label.setTextColor(60, 60, 60);
- q1Label.setFontSize(14);
- surveyContainer.addView(q1Label);
-
- var q1Group = new RadioButtonGroup();
- q1Group.setID("survey_q1");
- q1Group.setDefultSelect("ÂúÒâ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var verySatisfiedOption = new RadioButton();
- verySatisfiedOption.setText("·Ç³£ÂúÒâ");
- verySatisfiedOption.setGroup(q1Group);
-
- var satisfiedOption = new RadioButton();
- satisfiedOption.setText("ÂúÒâ");
- satisfiedOption.setGroup(q1Group);
-
- var neutralOption = new RadioButton();
- neutralOption.setText("Ò»°ã");
- neutralOption.setGroup(q1Group);
-
- var dissatisfiedOption = new RadioButton();
- dissatisfiedOption.setText("²»ÂúÒâ");
- dissatisfiedOption.setGroup(q1Group);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var q1Container = new Vertical();
- q1Container.setSpacing(10);
-
- var q1Row1 = new Horizontal();
- q1Row1.setSpacing(15);
- q1Row1.addView(verySatisfiedOption);
- q1Row1.addView(satisfiedOption);
-
- var q1Row2 = new Horizontal();
- q1Row2.setSpacing(15);
- q1Row2.addView(neutralOption);
- q1Row2.addView(dissatisfiedOption);
-
- q1Container.addView(q1Row1);
- q1Container.addView(q1Row2);
- surveyContainer.addView(q1Container);
-
- // ÎÊÌâ2
- var q2Label = new Label();
- q2Label.setText("2. ÄúʹÓòúÆ·µÄƵÂÊÊÇ£¿");
- q2Label.setTextColor(60, 60, 60);
- q2Label.setFontSize(14);
- surveyContainer.addView(q2Label);
-
- var q2Group = new RadioButtonGroup();
- q2Group.setID("survey_q2");
- q2Group.setDefultSelect("ÿÌìʹÓÃ");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var dailyOption = new RadioButton();
- dailyOption.setText("ÿÌìʹÓÃ");
- dailyOption.setGroup(q2Group);
-
- var weeklyOption = new RadioButton();
- weeklyOption.setText("ÿÖÜʹÓÃ");
- weeklyOption.setGroup(q2Group);
-
- var monthlyOption = new RadioButton();
- monthlyOption.setText("ÿÔÂʹÓÃ");
- monthlyOption.setGroup(q2Group);
-
- var rarelyOption = new RadioButton();
- rarelyOption.setText("ºÜÉÙʹÓÃ");
- rarelyOption.setGroup(q2Group);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var q2Container = new Vertical();
- q2Container.setSpacing(10);
-
- var q2Row1 = new Horizontal();
- q2Row1.setSpacing(15);
- q2Row1.addView(dailyOption);
- q2Row1.addView(weeklyOption);
-
- var q2Row2 = new Horizontal();
- q2Row2.setSpacing(15);
- q2Row2.addView(monthlyOption);
- q2Row2.addView(rarelyOption);
-
- q2Container.addView(q2Row1);
- q2Container.addView(q2Row2);
- surveyContainer.addView(q2Container);
-
- // ÎÊÌâ3
- var q3Label = new Label();
- q3Label.setText("3. Äú»áÍÆ¼ö¸øÅóÓÑÂð£¿");
- q3Label.setTextColor(60, 60, 60);
- q3Label.setFontSize(14);
- surveyContainer.addView(q3Label);
-
- var q3Group = new RadioButtonGroup();
- q3Group.setID("survey_q3");
- q3Group.setDefultSelect("»áÍÆ¼ö");
-
- // ´´½¨µ¥Ñ¡°´Å¥²¢¹ØÁªµ½×é
- var definitelyOption = new RadioButton();
- definitelyOption.setText("¿Ï¶¨»á");
- definitelyOption.setGroup(q3Group);
-
- var yesOption = new RadioButton();
- yesOption.setText("»áÍÆ¼ö");
- yesOption.setGroup(q3Group);
-
- var maybeOption = new RadioButton();
- maybeOption.setText("¿ÉÄÜ»á");
- maybeOption.setGroup(q3Group);
-
- var noOption = new RadioButton();
- noOption.setText("²»»á");
- noOption.setGroup(q3Group);
-
- // Ìí¼Óµ¥Ñ¡°´Å¥µ½ÈÝÆ÷
- var q3Container = new Vertical();
- q3Container.setSpacing(10);
-
- var q3Row1 = new Horizontal();
- q3Row1.setSpacing(15);
- q3Row1.addView(definitelyOption);
- q3Row1.addView(yesOption);
-
- var q3Row2 = new Horizontal();
- q3Row2.setSpacing(15);
- q3Row2.addView(maybeOption);
- q3Row2.addView(noOption);
-
- q3Container.addView(q3Row1);
- q3Container.addView(q3Row2);
- surveyContainer.addView(q3Container);
-
- // Ìá½»°´Å¥
- var submitSurveyButton = new Button();
- submitSurveyButton.setText("Ìá½»µ÷²é");
- submitSurveyButton.setColor(70, 130, 180);
- submitSurveyButton.setTextColor(255, 255, 255);
- submitSurveyButton.setWidth(150);
- submitSurveyButton.setHeight(45);
- submitSurveyButton.onClick(function() {
- var q1Radio = q1Group.currentSelectedRadio();
- var q2Radio = q2Group.currentSelectedRadio();
- var q3Radio = q3Group.currentSelectedRadio();
-
- var q1Answer = q1Radio ? q1Radio.getText() : "δѡÔñ";
- var q2Answer = q2Radio ? q2Radio.getText() : "δѡÔñ";
- var q3Answer = q3Radio ? q3Radio.getText() : "δѡÔñ";
-
- var result = "µ÷²é½á¹û:\n" +
- "1. ÂúÒâ¶È: " + q1Answer + "\n" +
- "2. ʹÓÃÆµÂÊ: " + q2Answer + "\n" +
- "3. ÍÆ¼öÒâÔ¸: " + q3Answer;
-
- printl(result);
- surveyResultLabel.setText(result);
- showToast("µ÷²éÌá½»³É¹¦£¡");
- });
- surveyContainer.addView(submitSurveyButton);
-
- var surveyResultLabel = new Label();
- surveyResultLabel.setText("µÈ´ýÌá½»µ÷²é...");
- surveyResultLabel.setTextColor(100, 100, 100);
- surveyResultLabel.setFontSize(12);
- surveyContainer.addView(surveyResultLabel);
-
- var surveyGetValueButton = new Button();
- surveyGetValueButton.setText("»ñÈ¡µ±Ç°Öµ");
- surveyGetValueButton.setColor(70, 130, 180);
- surveyGetValueButton.setTextColor(255, 255, 255);
- surveyGetValueButton.onClick(function() {
- var q1Radio = q1Group.currentSelectedRadio();
- var q2Radio = q2Group.currentSelectedRadio();
- var q3Radio = q3Group.currentSelectedRadio();
-
- var q1Answer = q1Radio ? q1Radio.getText() : "δѡÔñ";
- var q2Answer = q2Radio ? q2Radio.getText() : "δѡÔñ";
- var q3Answer = q3Radio ? q3Radio.getText() : "δѡÔñ";
-
- var result = "µ±Ç°Öµ:\n" +
- "1. ÂúÒâ¶È: " + q1Answer + "\n" +
- "2. ʹÓÃÆµÂÊ: " + q2Answer + "\n" +
- "3. ÍÆ¼öÒâÔ¸: " + q3Answer;
-
- printl(result);
- surveyResultLabel.setText(result);
- });
- surveyContainer.addView(surveyGetValueButton);
-
- comprehensivePage.addView(surveyContainer);
-
- // ·½·¨×ܽá
- var summarySection = new Horizontal();
- summarySection.setAlignment("center");
- summarySection.setBackgroundColor(220, 220, 225);
-
- var summarySectionLabel = new Label();
- summarySectionLabel.setText("·½·¨×ܽá");
- summarySectionLabel.setTextColor(60, 60, 60);
- summarySectionLabel.setFontSize(15);
- summarySection.addView(summarySectionLabel);
-
- comprehensivePage.addView(summarySection);
-
- var summaryContainer = new Vertical();
- summaryContainer.setSpacing(10);
- summaryContainer.setBackgroundColor(255, 255, 255);
-
- var summaryLabel = new Label();
- summaryLabel.setText("RadioButtonGroupºËÐÄ·½·¨×ܽ᣺\n\n" +
- "1. setID(id) - ÉèÖÿؼþΨһ±êʶ·û\n" +
- " ÓÃ;£ºÎªµ¥Ñ¡°´Å¥×éÉèÖÃID£¬±ãÓÚͨ¹ýconfig¶ÁÈ¡ÅäÖÃ\n" +
- " ʾÀý£ºrg.setID(\"abc\")\n\n" +
- "2. setDefultSelect(value) - ÉèÖÃĬÈÏÑ¡ÖÐÏî\n" +
- " ÓÃ;£º³õʼ»¯Ê±×Ô¶¯Ñ¡ÖÐÖ¸¶¨µÄÑ¡Ïî\n" +
- " ʾÀý£ºrg.setDefultSelect(\"ÄÐ\")\n\n" +
- "3. currentSelectedRadio() - »ñÈ¡µ±Ç°Ñ¡ÖÐÏî\n" +
- " ÓÃ;£º»ñÈ¡Óû§µ±Ç°Ñ¡ÔñµÄÑ¡Ïî\n" +
- " ʾÀý£ºrg.currentSelectedRadio()");
- summaryLabel.setTextColor(60, 60, 60);
- summaryLabel.setFontSize(11);
- summaryLabel.setBackgroundColor(245, 245, 255);
- summaryContainer.addView(summaryLabel);
-
- comprehensivePage.addView(summaryContainer);
-
- // ====================== µÚÎåÒ³£º·µ»Ø×ÀÃæ ======================
- var returnPage = new Vertical();
- returnPage.setSpacing(30);
- returnPage.setBackgroundColor(245, 248, 250);
- returnPage.setAlignment("center");
-
- var returnHeader = new Horizontal();
- returnHeader.setAlignment("center");
- returnHeader.setBackgroundColor(70, 130, 180);
-
- var returnHeaderLabel = new Label();
- returnHeaderLabel.setText("·µ»Ø×ÀÃæ");
- returnHeaderLabel.setTextColor(255, 255, 255);
- returnHeaderLabel.setFontSize(20);
- returnHeader.addView(returnHeaderLabel);
-
- returnPage.addView(returnHeader);
-
- var returnDesc = new Label();
- returnDesc.setText("µã»÷Ï·½°´Å¥·µ»Ø×ÀÃæ");
- returnDesc.setTextColor(100, 100, 100);
- returnDesc.setFontSize(16);
- returnDesc.setTextAlignment("center");
- returnPage.addView(returnDesc);
-
- var returnButton = new Button();
- returnButton.setText("·µ»Ø×ÀÃæ");
- returnButton.setColor(255, 99, 71); // ·¬ÇѺìÉ«±³¾°
- returnButton.setTextColor(255, 255, 255); // °×É«ÎÄ×Ö
- returnButton.setWidth(180);
- returnButton.setHeight(50);
- returnButton.onClick(function() {
- printl("·µ»Ø×ÀÃæ°´Å¥±»µã»÷");
- tab.dismiss();
- showToast("ÒÑ·µ»Ø×ÀÃæ");
- });
- returnPage.addView(returnButton);
-
- // ====================== Ìí¼ÓËùÓÐÒ³Ãæµ½TabView ======================
- tab.addView(0, basicPage);
- tab.addView(1, advancedPage);
- tab.addView(2, dynamicPage);
- tab.addView(3, comprehensivePage);
- tab.addView(4, returnPage);
-
- printl("RadioButtonGroupʾÀýÊÓͼÌí¼ÓÍê³É");
- });
- // ÏÔʾÌáʾÐÅÏ¢º¯Êý
- function showToast(message) {
- printl("Ìáʾ: " + message);
- }
- // ÈÕÖ¾Êä³öº¯Êý
- function printl(message) {
- console.log("[RadioButtonGroup Example] " + message);
- }
- // ´úÂë˵Ã÷£º
- // 1. ±¾Ê¾ÀýÈ«ÃæÕ¹Ê¾ÁËRadioButtonGroupµÄÈý¸öºËÐÄ·½·¨£ºsetID¡¢setDefultSelect¡¢currentSelectedRadio
- // 2. µÚһҳչʾÁË»ù´¡·½·¨µÄµ¥¶ÀʹÓúʹúÂëʾÀý
- // 3. µÚ¶þҳչʾÁËRadioButtonGroupÔÚʵ¼ÊÓ¦Óó¡¾°ÖеÄʹÓã¬ÈçÓû§ÉèÖá¢±íµ¥Ñ¡ÔñµÈ
- // 4. µÚÈýҳչʾÁ˶¯Ì¬´´½¨ºÍ¹ÜÀíRadioButtonGroupµÄ·½·¨
- // 5. µÚËÄҳչʾÁË×ÛºÏÓ¦Óó¡¾°£¬°üÀ¨ÍêÕûµÄÎʾíµ÷²éʾÀý
- // 6. ´úÂë×ñÑAIWROKƽ̨µÄ·½·¨¹æ·¶£¬Ê¹ÓÃES5Óï·¨
- // 7. ËùÓÐʾÀý¶¼°üº¬ÏêϸµÄ×¢ÊͺÍ˵Ã÷
- // 8. ¿ÉÒÔ¸ù¾Ýʵ¼ÊÐèÇóÐ޸ĺÍÀ©Õ¹¹¦ÄÜ
¸´ÖÆ´úÂë
|
|