How can I display spesific text and play spesific sound for each row in tableView ?

Hi everybody,

How can I display spesific text and play different spesific sounds for each row in tableView ? Just like when I press row 1, it displays “row 1 is ready for you” and play the sound for this row ? And here is my code ;

local widget = require( "widget" ) -- create a constant for the left spacing of the row content local LEFT\_PADDING = 10 --Set the background to white display.setDefault( "background", 1, 1, 1 ) --Create a group to hold our widgets & images local widgetGroup = display.newGroup() -- The gradient used by the title bar local titleGradient = { type = 'gradient', color1 = { 189/255, 203/255, 220/255, 255/255 }, color2 = { 89/255, 116/255, 152/255, 255/255 }, direction = "down" } -- Create toolbar to go at the top of the screen local titleBar = display.newRect( display.contentCenterX, 0, display.contentWidth, 75 ) titleBar:setFillColor( 0, 191/255, 255/255 ) titleBar.y = display.screenOriginY + titleBar.contentHeight \* 0.5 -- create embossed text to go on toolbar local titleText = display.newEmbossedText( "YEMEK", 45, titleBar.y, native.systemFontBold, 20 ) -- create a shadow underneath the titlebar (for a nice touch) local shadow = display.newImage( "shadow.png" ) shadow.anchorX = 0; shadow.anchorY = 0 -- TopLeft anchor shadow.x, shadow.y = 0, titleBar.y + titleBar.contentHeight \* 0.5 shadow.xScale = 320 / shadow.contentWidth shadow.alpha = 0.45 --Text to show which item we selected local itemSelected2 = display.newImage( "bg.jpg", 0, 0 ) itemSelected2.x = display.contentWidth + itemSelected2.contentWidth itemSelected2.y = display.contentCenterY widgetGroup:insert( itemSelected2 ) local itemSelected = display.newText( "You selected", 0, 0, native.systemFontBold, 24 ) itemSelected:setFillColor( 1 ) itemSelected.x = display.contentWidth + itemSelected.contentWidth \* 0.5 itemSelected.y = display.contentCenterY widgetGroup:insert( itemSelected ) -- Forward reference for our back button & tableview local backButton, list local rowTitles = {} -- Handle row rendering local function onRowRender( event ) local phase = event.phase local row = event.row local isCategory = row.isCategory -- in graphics 2.0, the group contentWidth / contentHeight are initially 0, and expand once elements are inserted into the group. -- in order to use contentHeight properly, we cache the variable before inserting objects into the group local groupContentHeight = row.contentHeight local rowTitle = display.newText( row, rowTitles[row.index], 0, 0, native.systemFontBold, 16 ) -- in Graphics 2.0, the row.x is the center of the row, no longer the top left. rowTitle.x = LEFT\_PADDING -- we also set the anchorX of the text to 0, so the object is x-anchored at the left rowTitle.anchorX = 0 rowTitle.y = groupContentHeight \* 0.5 rowTitle:setFillColor( 0, 0, 0 ) if not isCategory then local rowArrow = display.newImage( row, "rowArrow.png", false ) rowArrow.x = row.contentWidth - LEFT\_PADDING -- we set the image anchorX to 1, so the object is x-anchored at the right rowArrow.anchorX = 1 -- we set the image anchorX to 1, so the object is x-anchored at the right rowArrow.y = groupContentHeight \* 0.5 end end -- Hande row touch events local function onRowTouch( event ) local phase = event.phase local row = event.target if "press" == phase then print( "Pressed row: " .. row.index ) elseif "release" == phase then -- Update the item selected text itemSelected.text = "seçtiniz: " .. rowTitles[row.index] --Transition out the list, transition in the item selected text and the back button -- The table x origin refers to the center of the table in Graphics 2.0, so we translate with half the object's contentWidth transition.to( list, { x = - list.contentWidth \* 0.5, time = 400, transition = easing.outExpo } ) transition.to( itemSelected, { x = display.contentCenterX, time = 400, transition = easing.outExpo } ) transition.to( backButton, { alpha = 1, time = 400, transition = easing.outQuad } ) transition.to(itemSelected2, { x = display.contentCenterX, time = 400, transition = easing.outExpo } ) print( "Tapped and/or Released row: " .. row.index ) end end -- Create a tableView list = widget.newTableView { top = 32, width = 320, height = 448, maskFile = "mask-320x448.png", onRowRender = onRowRender, onRowTouch = onRowTouch, } --Insert widgets/images into a group widgetGroup:insert( list ) widgetGroup:insert( titleBar ) widgetGroup:insert( titleText ) widgetGroup:insert( shadow ) --Items to show in our list local listItems = { { title = "Kahvaltı", items = { "Kahve", "Simit", "Mısır Gevreği", "Tost" } }, { title = "Öğle Yemeği", items = { "Sandviç", "Taco", "Erişte", "Çorba", "Patates Kızartması" } }, { title = "Akşam Yemeği", items = { "Pizza", "Hamburger", "Biftek", "Sığır Eti", "Kuzu Eti" } }, { title = "Tatlı", items = { "Elmalı Turta", "Dondurma", "Kek", "Çikolata" } }, } --Handle the back button release event local function onBackRelease() --Transition in the list, transition out the item selected text and the back button -- The table x origin refers to the center of the table in Graphics 2.0, so we translate with half the object's contentWidth transition.to( list, { x = list.contentWidth \* 0.5, time = 400, transition = easing.outExpo } ) transition.to( itemSelected, { x = display.contentWidth + itemSelected.contentWidth \* 0.5, time = 400, transition = easing.outExpo } ) transition.to( backButton, { alpha = 0, time = 400, transition = easing.outQuad } ) transition.to(itemSelected2, { x = display.contentWidth + itemSelected.contentWidth , time = 400, transition = easing.outExpo } ) end --Create the back button backButton = widget.newButton { width = 298, height = 56, label = "Geri", labelYOffset = - 1, onRelease = onBackRelease } backButton.alpha = 0 backButton.x = display.contentCenterX backButton.y = display.contentHeight - backButton.contentHeight backButton:setFillColor( 1 ) widgetGroup:insert( backButton ) ---[[\*\*Remove This\*\* -- insert rows into list (tableView widget) for i = 1, #listItems do --Add the rows category title rowTitles[ #rowTitles + 1] = listItems[i].title --Insert the category list:insertRow{ rowHeight = 24, rowColor = { default = { 0, 191/255 , 255/255 }, }, isCategory = true, } --Insert the item for j = 1, #listItems[i].items do --Add the rows item title rowTitles[#rowTitles + 1] = listItems[i].items[j] --Insert the item list:insertRow{ rowHeight = 40, --rowColor = { over = { 135/255, 206/255, 250/255 } }, isCategory = false, listener = onRowTouch } end end --]]