如何动态加载下拉框,XML内容
Xml代码
<choice>
<choiceradiogroup>
<_renderer>
<![CDATA[<radiobutton><_value>${itemValue}</_value>${itemName}</radiobutton>]]>
</_renderer>
<_items>@{itemList}</_items>
</choiceradiogroup>
</choice>
<choice>
<choiceradiogroup>
<_renderer>
<![CDATA[<radiobutton><_value>${itemValue}</_value>${itemName}</radiobutton>]]>
</_renderer>
<_items>@{itemList}</_items>
</choiceradiogroup>
</choice>
java代码 DataProvide
Java代码
public class combo implements Frame {
protected Screen screen;
// Associate our data provider to the frame
protected MyDataProvider dataProvider = new MyDataProvider();
public void onAdded() {
// TODO Auto-generated method stub
dataProvider.initializeChoices();
screen = Kuix.loadScreen("combo.xml", dataProvider);
screen.setCurrent();
}
public boolean onMessage(Object identifier, Object[] arg1) {
// TODO Auto-generated method stub
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;
}
// let the next frames in the stack, process the message
return true;
}
public void onRemoved() {
// TODO Auto-generated method stub
screen.cleanUp();
// unreference the screen object to free the memory
screen = null;
}
}
class MyDataProvider extends DataProvider {
private static final String ITEM_LIST = "itemList";
public void initializeChoices() {
for(int i=0;i<2;i++) {
ChoiceListItem item = new ChoiceListItem();
item.setItemName("ItemName " + i);
item.setItemValue("ItemValue " + i);
addItem(ITEM_LIST, item);
}
}
}
class ChoiceListItem extends DataProvider{
private String itemValue;
private String itemName;
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemValue() {
return itemValue;
}
public void setItemValue(String itemValue) {
this.itemValue = itemValue;
}
protected Object getUserDefinedValue(String property) {
// handle custom properties requests
if ("itemName".equals(property)) {
return this.itemName;
}
if ("itemValue".equals(property)) {
return this.itemValue;
}
// default behavior if the property has not been found
return null;
}
}
public class combo implements Frame {
protected Screen screen;
// Associate our data provider to the frame
protected MyDataProvider dataProvider = new MyDataProvider();
public void onAdded() {
// TODO Auto-generated method stub
dataProvider.initializeChoices();
screen = Kuix.loadScreen("combo.xml", dataProvider);
screen.setCurrent();
}
public boolean onMessage(Object identifier, Object[] arg1) {
// TODO Auto-generated method stub
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;
}
// let the next frames in the stack, process the message
return true;
}
public void onRemoved() {
// TODO Auto-generated method stub
screen.cleanUp();
// unreference the screen object to free the memory
screen = null;
}
}
class MyDataProvider extends DataProvider {
private static final String ITEM_LIST = "itemList";
public void initializeChoices() {
for(int i=0;i<2;i++) {
ChoiceListItem item = new ChoiceListItem();
item.setItemName("ItemName " + i);
item.setItemValue("ItemValue " + i);
addItem(ITEM_LIST, item);
}
}
}
class ChoiceListItem extends DataProvider{
private String itemValue;
private String itemName;
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getItemValue() {
return itemValue;
}
public void setItemValue(String itemValue) {
this.itemValue = itemValue;
}
protected Object getUserDefinedValue(String property) {
// handle custom properties requests
if ("itemName".equals(property)) {
return this.itemName;
}
if ("itemValue".equals(property)) {
return this.itemValue;
}
// default behavior if the property has not been found
return null;
}
}
获取下拉框当前选择项的数值
Java代码
<choice>
<choiceRadiogroup id="chk1">
。。。
<button onAction="choicechange(#chk1.selectedradiobutton)">get</button>
<choice>
<choiceRadiogroup id="chk1">
。。。
<button onAction="choicechange(#chk1.selectedradiobutton)">get</button> 里面的事件处理代码:
Java代码
RadioButton rad=(RadioButton)arguments[0];
Kuix.alert((String)rad.getValue());
RadioButton rad=(RadioButton)arguments[0];
Kuix.alert((String)rad.getValue()); 其他说明:
1 onAction是在弹出下拉列表时触发,不是修改选择项后触发的
2 getTag返回的是标签“RadioButton”,由于列表中可能不只包含文字,所以无论ChoiceGroup还是RadioButton都不提供读取当前选中文字的功能,如果确实需要返回里面的文字,可以考虑把文字写入ID,前面加适当前缀,但是必须保证唯一
3 接2,实机上下拉框是一个容器,如果其中只包含文本的话可以用下面的代码获取其中的文本
Java代码
((Text)rad.getChild()).getText();
((Text)rad.getChild()).getText(); 4 实际上上面的触发事件用choicechange(#chk1.value)可以直接传入选中项的值
转载于:http://shappy1978.iteye.com
分享到:
相关推荐
AJAXA例子--动态加载下拉框 AJAXA例子--动态加载下拉框
下拉框选择背景.rar下拉框选择背景.rar下拉框选择背景.rar下拉框选择背景.rar下拉框选择背景.rar下拉框选择背景.rar
直接上代码吧~ 用户类型 width=180> <template slot-scope=scope> <el v-model=scope.row.roleID placeholder=请选择 change=changeRole($event,scope)> <el-option v-for=item in roles ...
支持ext3.0以上版本,希望大家能用到-----------------------------------
uni-app下拉框实现,纯原生写法
自定义-js模仿下拉框效果 测过IE6/7/8 ff5.0 chremo 12.0. 是用li来模仿的,隐藏存在一个select方便form提交,其实既然只是获取选定后的数据,也可以用隐藏的input:text 代替 (如果出现什么异常可以给本人留言)
JavaScript应用实例-悬浮窗下拉框.js
bootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-select 下拉框demobootstrap-...
AutoJs源码-悬浮窗下拉框。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!...
jquery--下拉框的实现jquery--下拉框的实现
下拉框选择显示图片.rar下拉框选择显示图片.rar下拉框选择显示图片.rar下拉框选择显示图片.rar下拉框选择显示图片.rar下拉框选择显示图片.rar
下拉框显示当前时间.rar下拉框显示当前时间.rar下拉框显示当前时间.rar下拉框显示当前时间.rar下拉框显示当前时间.rar下拉框显示当前时间.rar
下拉框的新特性.rar
点击单元格,自动弹出下拉框,根据输入逐步搜索,模糊搜索,直接选择
bootstrap-select下拉框
jquery动态创建联动下拉框和jquery动态创建下拉框
主要介绍了js公式编辑器 - 自定义匹配规则 - 带提示下拉框 - 动态获取光标像素坐标的方法,,需要的朋友可以参考下
AJAX-DWR下拉框级联AJAX-DWR下拉框级联 真正实用的`仅供参考
自定义类似网页中的下拉框组件,可设置comboBox背景,字体颜色,整体颜色,更改大小,获取选中项的值、设置弹出框的大小。