我在iOS应用中创建了单选按钮,如下图所示。我想在用户点击任何一个单选按钮后立即将剩余单选按钮的图像从选中更改为未选中。
以下是我的eventlistener代码。
results.extend([(p, [os.path.join(p,f) for f in files]) for p, subdirs, files in os.walk(datadir)])
results.extend((p, [os.path.join(p,f) for f in files]) for p, subdirs, files in os.walk(datadir))
代码中的for循环无法将其他单选按钮的图像从选中更改为
你能告诉我我做错了什么吗?如果您想进一步澄清,也请告诉我。感谢Advcance。
答案 0 :(得分:1)
如果您使用的是ListView,则应使用updateItemAt方法。
从Appcelerator文档(http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ListItem)中查看此示例:
$.listView.addEventListener('itemclick', function(e) {
var item = $.section.getItemAt(e.itemIndex);
if (item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_NONE) {
item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK;
item.properties.color = 'red';
} else {
item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_NONE;
item.properties.color = 'black';
}
$.section.updateItemAt(e.itemIndex, item);
});
答案 1 :(得分:0)
你确定嵌套是否正确?那么e.source.parent.parent.children[t].children[0].image = "/images/radio-button_ori.png";
是您要更改的单选按钮?
尝试其他设置:
你在使用Alloy吗?然后只需为图像提供一个自己的ID并直接访问它。
如果不是:将所有的radiobutton图像推入一个数组,向vwBottomContainer添加一个位置并从阵列中访问radiobutton:
var rbts = [];
rbts.push(radioButtonImage1);
rbts.push(radioButtonImage2);
rbts.push(radioButtonImage3);
outerViewWithClickEvent1.radioID = 0;
outerViewWithClickEvent2.radioID = 1;
outerViewWithClickEvent3.radioID = 2;
在onClick事件中:
rbts[e.source.radioID].image = "newImage.jpg";
如果您显示单选按钮的代码/视图,它也会有所帮助。