I am trying to achieve the functionality like after I update row element from the label to textfield of listview, it should automatically select all the value in the textfield. I am able to do it by adding the listener to the "onFocus" of the textfield but it's not getting auto focused when I change update the row. so to autoFocus i am calling the "item.Focus()" on the reference of the textfield but it is giving the error as can't call the function of the undefined. Can't we call the Focus() method on the reference element of the row in the listview ?
Titanium CLI version : 3.4.0 Titanium SDK version : 3.4.0.v20140916181713
index.xml :
<Alloy> <Window class="container"> <ListView id="streamListView" top="50dp"> <Templates> <ItemTemplate name="template" id="template"> <Label bindId="label" height="Ti.UI.FILL" width="Ti.UI.FILL"></Label> <TextField bindId="textField" height="0" width="0" onFocus="changeText"></TextField>> </ItemTemplate> </Templates> <ListSection id="section"> </ListSection> </ListView> </Window> </Alloy>index.js
var listData = []; // add the labels in the listview. for ( i = 0; i < 10; i++) { var item = { template : 'template', label : { text : ("ROW NO. : " + i) } }; listData[i] = item; } // change the row from label to texfield. function changeRow(e){ var item = $.section.getItemAt(e.itemIndex); var item = { template : 'template', textField : { value : "textField", width : Ti.UI.FILL, height : Ti.UI.FILL } }; // update the row with the changed text $.section.updateItemAt(e.itemIndex,item); // again get the recent item of the row. item = $.section.getItemAt(e.itemIndex)["textField"]; Ti.API.debug("row item : " + JSON.stringify(item)); // fire event manually. By uncommenting the below it's giving the error.Can't we fire the events of textField by using refernce? // item.focus(); } // change the textfields value. // called when the textfield is focused. function changeText(e){ Ti.API.error("called"); e.source.value = "changed text"; // can use the setSelection to select all the value in the textfield. } // on itemclick change the label to textfield. $.streamListView.addEventListener("itemclick",function(e){ changeRow(e); }); // add the items in the listview $.section.setItems(listData); // open the window. $.index.open();