Hi guys,
We have a situation in a project where we are displaying all the Facebook friends profile images and there name adjacent to profile images using the table view. The list view is working fine displaying all the Facebook friends profile images with their names the issue is after selecting (I am highlighting using a setFillColor ) the random friends (Rows) and scrolling the list (Bottom or Top) the highlighted background color vanishes making the selected rows look normal (It’s not persistence).Please find below the attached piece of lua code.
local selectedRowIndex = {}
local function isSelected(event)
local FBID=event.id;
if(table.indexOf(selectedRowIndex,FBID ) == nil) then
table.insert(selectedRowIndex, FBID)
return true
else
local FBIDIndex =table.indexOf(selectedRowIndex, FBID )
table.remove(selectedRowIndex, FBIDIndex)
return false
end
end
local function highlightRow(event)
local background = event.background
local row = event.row;
background:setFillColor( 84, 202, 255, 90 )
end
local function UnHighlightRow(event)
local background = event.background
local row = event.row;
background:setFillColor( 255, 255, 255, 255 )
end
local function onRowTouch( event )
--local row = event.target
local rowGroup = event.view
local rowImage
if event.phase == "press" then
if(isSelected(event) == true) then
--highlight row
highlightRow(event)
else
UnHighlightRow(event)
end
elseif event.phase == "swipeLeft" then
print( "Swiped left." )
elseif event.phase == "swipeRight" then
print( "Swiped right." )
elseif event.phase == "release" then
print( "You touched row #" .. event.index )
end
return true
end
-- onRender listener for the tableView
local function onRowRender( event )
local row = event.target;
local rowGroup = event.view;
local index = event.index;
local FBid = data[index].id;
local defaultFB=display.newImage( "images/findFriend/default\_Friend.png", 7,6)
rowGroup:insert(defaultFB)
-- Adding user image
local function networkListener( event )
if ( event.isError ) then
print ( "Network error - download failed" )
else
rowGroup:insert(event.target)
event.target.x = 32
event.target.y = 32
end
print ( "RESPONSE: " .. event.response )
end
display.loadRemoteImage("http://graph.facebook.com/"..FBid.."/picture", "GET", networkListener,"friendProfile\_pic\_"..FBid..".png", system.TemporaryDirectory,1050,1050)
FBFriendName = display.newText( data [index].name,150, 37,350,50, "Helvetica", 20 )
FBFriendName:setReferencePoint( display.CenterLeftReferencePoint)
FBFriendName.x = 72
FBFriendName.y = 40
FBFriendName:setTextColor( 179,179,179 )
rowGroup:insert( FBFriendName )
end
function FBdataHandler(event)
display.setStatusBar( display.HiddenStatusBar )
display.setDefault( "background", 255, 255, 255 )
local listOptions = {
top =137+display.screenOriginY,
height = 650
}
list = widget.newTableView( listOptions)
native.setActivityIndicator( true )
--#data - Contains all the friends name and ID
for i=1, #data do
print("Facebook friend: " .. data[i].name .. ", id: " .. data[i].id..",Picture : http://graph.facebook.com/"..data[i].id.."/picture")
local rowHeight, rowColor, lineColor, isCategory
rowHeight=65
lineColor={110, 233, 255,255}
list:insertRow{
id= data[i].id,
onEvent=onRowTouch,
onRender=onRowRender,
listener = rowListener,
height=rowHeight,
isCategory=isCategory,
rowColor=rowColor,
lineColor=lineColor
}
end
fbgroup:insert( list )
native.setActivityIndicator( false)
end
And one more thing as i am using display.loadRemoteImage every time i scroll the list the friend profile picture will blink (May be re downloading) i don’t want this to happen.
Please suggest what to do. [import]uid: 188904 topic_id: 33912 reply_id: 333912[/import]