下面是一个通过设置DataProvider影响界面的例子,用按钮控制一个当选框的值。
XML界面
<screen> <_title>%DYNAMIC_DISPLAY%</_title> <container style="layout:inlinelayout(false,fill);align:center"> <text style="padding: 0 0 15 0">%PLATFORM_NAME(@{platformName})%</text> <container style="layout:gridlayout(2,1)"> <button onAction="btn_female" shortcuts="1">%FEMALE_BTN%</button> <button onAction="btn_male" shortcuts="2">%MALE_BTN%</button> </container> <text>%GENDER(@{gender})%</text> <radioGroup onChange=""> <_value>@{gender}</_value> <radioButton value="F" enabled="true">female</radioButton> <radioButton value="M" enabled="true">male</radioButton> </radioGroup> </container> <screenFirstMenu onAction="back">返u22238 </screenFirstMenu> <screenSecondMenu> %MORE% <menuPopup> <menuItem onAction="about"> %ABOUT% </menuItem> <menuItem onAction="exitConfirm"> %EXIT% </menuItem> </menuPopup> </screenSecondMenu> </screen>
事件处理:
public boolean onMessage(Object identifier, Object[] arg1) {
if ("back".equals(identifier)) {
// remove the current frame from the framehandler stack
Kuix.getFrameHandler().removeFrame(this);
// and display the main screen
Kuix.getFrameHandler().getTopFrame().onAdded();
// do not propagate the message through the rest of the frame stack
return false;
} else if ("btn_female".equals(identifier)) {
// use the data provider to set its value
dataProvider.setGender("F");
} else if ("btn_male".equals(identifier)) {
// use the data provider to set its value
dataProvider.setGender("M");
}
// let the next frames in the stack, process the message
return true;
}
运行结果: