Hi, I'm want to make a basic list of layouts with a loop, but the function SetOnTouch is called usually 2 or 3 times. I don't know why; someone can help me to fix this?
This is the code:
function OnStart() {
//Create a basic layout with a Scroller
lay = app.CreateLayout('Absolute');
scroll = app.CreateScroller( 1.0, 1.0 );
lay.AddChild( scroll );
app.AddLayout(lay);
layScroll = app.CreateLayout('Linear','Vertical');
scroll.AddChild(layScroll);
list = [[1,2,'green'],[3,4,'blue'],[5,6,'yellow'],[7,8,'#007E80']];
list.forEach(lays);
}
//Here I want to create a small layout and add it to layScroll
function lays(item,index) {
//Create the layout
layout = app.CreateLayout('Absolute');
layout.SetBackColor(item[2]);
layout.SetSize(1,0.2);
//Here I will call layout_OnTouch when layout is touched
layout.SetOnTouch(layout_OnTouch);
//Add an optional option to layout
layout.index = index;
//Add first text
txt1 = app.CreateText(item[0]);
txt1.SetPosition(0.5,0.05);
layout.AddChild(txt1);
//Add second text
txt2 = app.CreateText(item[1]);
txt2.SetPosition(0.1,0.1);
layout.AddChild(txt2);
//Add layout to layScroll
layScroll.AddChild(layout);
}
function layout_OnTouch() {
app.ShowPopup(this.index);
}
This is the debug output when I touch every layout only one time (in this case I touched the first layout):
App.ShowPopup( 0 )
App.ShowPopup( 0 )