I am trying to list images of restaurants in a scrollview but make them buttons. I am downloading the list with json and then loop through the results. I have the remote image file name so I can download it. But how do I make it download each one as the list is shown?
Here is the code i have in my listener when the data is retrieved from my web service / sql server.
local function networkListener( event ) local ct = 1 data[ct] = {} if ( event.isError ) then print( "Network error!") native.showAlert( "Error", "A network error has occured. Please make sure you have a network connection on your device and try again.", { "OK" } ) else myNewData = event.response local myTable = json.decode(myNewData) Results = #myTable.RestList for i=1,Results do local RestNo2 = myTable.RestList[i].RestNo local Name2 = myTable.RestList[i].Name local Address2 = myTable.RestList[i].Address local City2 = myTable.RestList[i].City local State2 = myTable.RestList[i].State local Zip2 = myTable.RestList[i].Zip local CityStateZip2 = RestList.Apartment[i].CityStateZip local Latitude2 = myTable.RestList[i].Latitude local Longitude2 = myTable.RestList[i].Longitude local Deliver2 = myTable.RestList[i].Deliver local Picture2 = myTable.RestList[i].Picture local CatName2 = myTable.RestList[i].CatName local PWidth2 = myTable.RestList[i].PWidth local PHeight2 = myTable.RestList[i].PHeight data[ct] = {} data[ct].RestNo = RestNo2 data[ct].Name = Name2 data[ct].Address = Address2 data[ct].City = City2 data[ct].State = State2 data[ct].Zip = Zip2 data[ct].CityStateZip = CityStateZip2 data[ct].Latitude = Latitude2 data[ct].Longitude = Longitude2 data[ct].Deliver = Deliver2 data[ct].Picture = Picture2 data[ct].CatName = CatName2 data[ct].PWidth = PWidth2 data[ct].PHeight = PHeight2 ct = ct + 1 end --Show restaurant pictures with links in listview local Col = 1 for i=1,#data do imgRest[i] = widget.newButton { width = data[i].PWidth, height = data[i].PHeight, defaultFile = (picture file goes here), overFile = (picture file goes here), label = "", onEvent = btnRestButtonEvent } imgRest[i].anchorX = 0 imgRest[i].anchorY = 0 imgRest[i].y = Top8 imgRest[i].x = 5 imgRest[i].id = (picture file goes here) scrollView:insert( imgRest[i] ) CT1 = CT1 + 1 Top8 = Top8 + data[i].PHeight end if ct == 1 then native.showAlert( " ", "There are no restaurants to show for the current location..", { "OK" } ) end end
Thanks,
Warren