Problem! Create some layouts in a loop

39 views
Skip to first unread message

omissam2002

unread,
Aug 20, 2019, 10:26:11 AM8/20/19
to DroidScript
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 )

Symbroson

unread,
Aug 20, 2019, 10:28:30 AM8/20/19
to DroidScript
SetOnTouch fires Down, Move and Up events.
Use SetOnTouchUp instead.

omissam2002

unread,
Aug 20, 2019, 11:24:56 AM8/20/19
to DroidScript
Thanks!

Dan Flemming

unread,
Aug 20, 2019, 12:48:40 PM8/20/19
to DroidScript
I think this may have answered my problem in my post directly above this on.
SetOnTouchUp() may be the answer I seek.

Thanks...
D
Reply all
Reply to author
Forward
0 new messages