reset butons color into cycle for

Hi…

I must insert 14 buttons in a scroll…

I used a circle for to work better and it work fine. But i 've a issue with background color of widget buttons…

I must change color when i press button, and when i press another button the color buttons must be reset. I tried different method but i failed.

Can someone help me … I post the code.

local widget = require "widget" local scroll local button local button1 = {} button1[1] = {label = "Accend.\n.05.00" , id = "Acc"} button1[2] = {label = "Adesivi\n .08.00" , id = "Ade" } button1[3] = {label = "Bor\n .07.0" , id = "Brs" } button1[4] = {label = "Bra.\n .16.00", id = "BRC" } button1[5] = {label = "Cam.\n .11.00", id = "Camp" } button1[6] = {label = "Capp.\n .27.00" , id = "Cap" } button1[7] = {label = "Cuch.\n .04.00" , id = "Cuc" } button1[8] = {label = "Grmb.\n .14.00" , id = "GRB" } button1[9] = {label = "Man.\n.02.00" , id = "Magn" } button1[10] = {label = "Pen\n.15.00" , id = "PE" } button1[11] = {label = "Cll.\n.20.00" , id = "CO" } button1[12] = {label = "Prt.\n .01.00" , id = "PO" } button1[13] = {label = "Spl\n .03.00" , id = "SP" } button1[14] = {label = "Stpp.\n .12.00" , id = "Stap" } button1[15] = {label = "Tze\n .10.00", id = "Taz" } button1[16] = {label = "Tpe\n .06.00" , id = "Top" } local function press2(event) local target = event.target local phase = event.phase if (phase == "began") then button:setFillColor( 0.9,0.9,1 ) --reset buttons color (doesn't work) end if ( phase == "moved" ) then --FF local dy = math.abs( ( event.y - event.yStart ) ) -- If the touch on the button has moved more than 10 pixels, -- pass focus back to the scroll view so it can continue scrolling if ( dy \> 2 ) then --GG scroll:takeFocus( event ) end end if (phase == "ended") then target:setFillColor( 0.9,0,0 ) -- it works fine end end scroll = widget.newScrollView { left = 35, top = 90, width = display.contentWidth -70 , height = display.contentCenterY - 160 , hideBackground = true, rightPadding = 50 , bottomPadding = 30, horizontalScrollDisabled = false, verticalScrollDisabled = true, listener = scrollListener, scrollWidth = 0, scrollHeight = -10 } for o = 1,#button1 do button= widget.newButton( { label = button1[o].label, fontSize = 16, labelColor = { default={ 0, 0, 0.4 , 1}, over={ 0, 0, 0, 0.5 } }, id = button1[o].id, onEvent = press2, emboss = false, -- Properties for a rounded rectangle button shape = "roundedRect", width = 70, height = 50, cornerRadius = 2, fillColor = { default={ 0.9,0.9,1}, over={0.8, 0.8, 0.8} }, strokeColor = { default={0, 0.4, 1 }, over={0, 0.2, 0.8 } }, strokeWidth = 1 } ) button.anchorX= 0 button.x = - 75 + o \*80 button.y = display.contentCenterY- 200 scroll:insert(button) end

Best I can do.

local widget = require "widget" local scroll local button1 = {} local buttonHolder = {} button1[1] = {label = "Accend.\n.05.00" , id = "Acc"} button1[2] = {label = "Adesivi\n .08.00" , id = "Ade" } button1[3] = {label = "Bor\n .07.0" , id = "Brs" } button1[4] = {label = "Bra.\n .16.00", id = "BRC" } button1[5] = {label = "Cam.\n .11.00", id = "Camp" } button1[6] = {label = "Capp.\n .27.00" , id = "Cap" } button1[7] = {label = "Cuch.\n .04.00" , id = "Cuc" } button1[8] = {label = "Grmb.\n .14.00" , id = "GRB" } button1[9] = {label = "Man.\n.02.00" , id = "Magn" } button1[10] = {label = "Pen\n.15.00" , id = "PE" } button1[11] = {label = "Cll.\n.20.00" , id = "CO" } button1[12] = {label = "Prt.\n .01.00" , id = "PO" } button1[13] = {label = "Spl\n .03.00" , id = "SP" } button1[14] = {label = "Stpp.\n .12.00" , id = "Stap" } button1[15] = {label = "Tze\n .10.00", id = "Taz" } button1[16] = {label = "Tpe\n .06.00" , id = "Top" } local function press2(event) local target = event.target local phase = event.phase if ( phase == "moved" ) then --FF local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 2 ) then --GG scroll:takeFocus( event ) end end if (phase == "ended") then for i,v in pairs(buttonHolder) do v:setFillColor( 0.9,0.9,1 ) end target:setFillColor( 0.9,0,0 ) end end scroll = widget.newScrollView { left = 35, top = 90, width = display.contentWidth -70 , height = display.contentCenterY - 160 , hideBackground = true, rightPadding = 50 , bottomPadding = 30, horizontalScrollDisabled = false, verticalScrollDisabled = true, listener = scrollListener, scrollWidth = 0, scrollHeight = -10 } for o = 1,#button1 do local button= widget.newButton( { label = button1[o].label, fontSize = 16, labelColor = { default={ 0, 0, 0.4 , 1}, over={ 0, 0, 0, 0.5 } }, id = button1[o].id, onEvent = press2, emboss = false, -- Properties for a rounded rectangle button shape = "roundedRect", width = 70, height = 50, cornerRadius = 2, fillColor = { default={ 0.9,0.9,1}, over={0.8, 0.8, 0.8} }, strokeColor = { default={0, 0.4, 1 }, over={0, 0.2, 0.8 } }, strokeWidth = 1 }) button.anchorX= 0 button.x = - 75 + o \*80 button.y = display.contentCenterY- 200 scroll:insert(button) table.insert(buttonHolder,button) end 

 
Some work still needs to be done

cool…thanks :slight_smile:

Best I can do.

local widget = require "widget" local scroll local button1 = {} local buttonHolder = {} button1[1] = {label = "Accend.\n.05.00" , id = "Acc"} button1[2] = {label = "Adesivi\n .08.00" , id = "Ade" } button1[3] = {label = "Bor\n .07.0" , id = "Brs" } button1[4] = {label = "Bra.\n .16.00", id = "BRC" } button1[5] = {label = "Cam.\n .11.00", id = "Camp" } button1[6] = {label = "Capp.\n .27.00" , id = "Cap" } button1[7] = {label = "Cuch.\n .04.00" , id = "Cuc" } button1[8] = {label = "Grmb.\n .14.00" , id = "GRB" } button1[9] = {label = "Man.\n.02.00" , id = "Magn" } button1[10] = {label = "Pen\n.15.00" , id = "PE" } button1[11] = {label = "Cll.\n.20.00" , id = "CO" } button1[12] = {label = "Prt.\n .01.00" , id = "PO" } button1[13] = {label = "Spl\n .03.00" , id = "SP" } button1[14] = {label = "Stpp.\n .12.00" , id = "Stap" } button1[15] = {label = "Tze\n .10.00", id = "Taz" } button1[16] = {label = "Tpe\n .06.00" , id = "Top" } local function press2(event) local target = event.target local phase = event.phase if ( phase == "moved" ) then --FF local dy = math.abs( ( event.y - event.yStart ) ) if ( dy \> 2 ) then --GG scroll:takeFocus( event ) end end if (phase == "ended") then for i,v in pairs(buttonHolder) do v:setFillColor( 0.9,0.9,1 ) end target:setFillColor( 0.9,0,0 ) end end scroll = widget.newScrollView { left = 35, top = 90, width = display.contentWidth -70 , height = display.contentCenterY - 160 , hideBackground = true, rightPadding = 50 , bottomPadding = 30, horizontalScrollDisabled = false, verticalScrollDisabled = true, listener = scrollListener, scrollWidth = 0, scrollHeight = -10 } for o = 1,#button1 do local button= widget.newButton( { label = button1[o].label, fontSize = 16, labelColor = { default={ 0, 0, 0.4 , 1}, over={ 0, 0, 0, 0.5 } }, id = button1[o].id, onEvent = press2, emboss = false, -- Properties for a rounded rectangle button shape = "roundedRect", width = 70, height = 50, cornerRadius = 2, fillColor = { default={ 0.9,0.9,1}, over={0.8, 0.8, 0.8} }, strokeColor = { default={0, 0.4, 1 }, over={0, 0.2, 0.8 } }, strokeWidth = 1 }) button.anchorX= 0 button.x = - 75 + o \*80 button.y = display.contentCenterY- 200 scroll:insert(button) table.insert(buttonHolder,button) end 

 
Some work still needs to be done

cool…thanks :slight_smile: