主程序: itemEditDemo
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var arr:ArrayCollection =new ArrayCollection([{age:12, name:"Joe"},
{age:16, name:"Jorge"},
{age:19, name:"Jojo"},
{age:2, name:"James"},
{age:12, name:"Joaquin"}]);
public function processData(event:ListEvent):void{
//终止Event 中的默认动作
event.preventDefault();
//获得新的单元格编译器
list.editedItemRenderer.data=MultipleDataTypeEditor(list.itemEditorInstance).data;
//关闭单元格编译器
list.destroyItemEditor();
//通知列表控件来更新其显示。
list.dataProvider.notifyItemUpdate(list.editedItemRenderer);
}
]]>
</mx:Script>
<mx:List id="list" itemEditor="MultipleDataTypeEditor" dataProvider="{arr}"
itemEditEnd="processData(event)"
itemRenderer="MultipleDataTypeEditor"
width="350" editable="true" >
</mx:List>
</mx:Application>
渲染的编辑器:MultipleDataTypeEditor
package
{
import mx.containers.Canvas;
import mx.controls.TextInput;
public class MultipleDataTypeEditor extends Canvas
{
private var nameField:TextInput;
private var ageField:TextInput;
public function MultipleDataTypeEditor()
{
super();
nameField = new TextInput();
ageField = new TextInput();
addChild(nameField);
//focusEnabled 该值指示组件是否可以在用户单击它后获得焦点。
nameField.focusEnabled=false;
addChild(ageField);
nameField.focusEnabled=false;
ageField.x=100;
this.horizontalScrollPolicy="none";
}
override public function set data(value:Object):void{
super.data =value;
nameField.text=value.name;
ageField.text=value.age;
}
override public function get data():Object{
return {name:nameField.text,age:ageField.text} ;
}
}
}
2562

被折叠的 条评论
为什么被折叠?



