Lets work together to build a nice SearchBar sample app ...

hei i need the code bro can u post it in the forum for me to see i will be very grateful for your reply

hoochongyi95,

Here is my code.  I haven’t polished it up yet and it has alot of our formatting in it, but it does work well.  It pulls from a sqlite database and as the user types in the native text field, it narrows down the results.  Tested on an Android device and works great - pops up the keyboard and everything.

--------------------------------------------------------------------------------- -- SCENE NAME -- Scene notes go here --------------------------------------------------------------------------------- require "sqlite3" local globals = require( "globals" ) local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require( "widget" ) local ALSBLS = "ALS" local ShowingDoc = false local webView local SearchText = "" local OldSearchText = "" -- Clear previous scene storyboard.removeAll() local SearchTextArea local tapnum = 0 -- local forward references should go here -- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- Background color local bgImage = display.newRect( 0, 0, 380, 570 ) bgImage.strokeWidth = 0 bgImage:setFillColor( 0/255, 84/255, 166/255 ) bgImage:setStrokeColor( 0/255, 84/255, 166/255 ) bgImage.x = display.contentCenterX bgImage.y = display.contentCenterY group:insert(bgImage) -- Header 360 x 50 local bgHeader = display.newRect( 0, 0, 360, 50 ) bgHeader.strokeWidth = 0 bgHeader:setFillColor( 237/255, 237/255, 237/255 ) bgHeader:setStrokeColor( 237/255, 237/255, 237/255 ) bgHeader.x = display.contentCenterX bgHeader.y = 25 group:insert(bgHeader) local topText = display.newText( "Drugs", 20, 0, native.systemFontBold, 20 ) topText:setFillColor( 0 ) topText.y = 25 topText.x = display.contentCenterX group:insert(topText) -- back button local backBtn = display.newImage( "back.png" ) backBtn.x = 25 backBtn.y = 25 group:insert( backBtn) -- top Phone button local imgPhone = display.newImage( "callmain.png" ) imgPhone.x = display.contentWidth - 50 imgPhone.y = 25 imgPhone:addEventListener( "tap", function( event ) system.openURL( "tel:610-402-1473" ) end ) group:insert(imgPhone) local SearchTextArea local SearchBar = display.newImageRect( "SearchBar.png", 320, 40 ) SearchBar.anchorX = 0 SearchBar.anchorY = 0 SearchBar.x = 0 SearchBar.y = 51 group:insert(SearchBar) --local clck = display.newRect( 0, 0, 30, 30 ) --clck:setFillColor(1,1,1) --clck.anchorX = 0 --clck.anchorY = 0 --clck.x = 300 --clck.y = 51 --group:insert(clck) -- -- -- local navBarHeight = 50 local tabBarHeight = 0 -- data local myDataD = {} --local myData = {}; local int = 1 local doneDB = false local path = system.pathForFile("EMS\_DB.sqlite", system.DocumentsDirectory ) file = io.open( path, "r" ) if( file == nil )then -- Doesn't Already Exist, So Copy it In From Resource Directory pathSource = system.pathForFile( "EMS\_DB.sqlite", system.ResourceDirectory ) fileSource = io.open( pathSource, "rb" ) contentsSource = fileSource:read( "\*a" ) --Write Destination File in Documents Directory pathDest = system.pathForFile( "EMS\_DB.sqlite", system.DocumentsDirectory ) fileDest = io.open( pathDest, "wb" ) fileDest:write( contentsSource ) -- Done io.close( fileSource ) io.close( fileDest ) end -- handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" and doneDB==false) then db:close() end end local function reLoadData() print ("reLoadData") int = 1 myDataD = {} doneDB = false local mySQL if string.len(SearchText) \> 0 then mySQL = "SELECT DrugName from Drug\_Master WHERE DrugName LIKE '"..SearchText.."%' Order By DrugName" else mySQL = "SELECT DrugName from Drug\_Master Order By DrugName" end print(mySQL) --Go through my database selecting all the site names... local dbPath = system.pathForFile("EMS\_DB.sqlite", system.ResourceDirectory) local db = sqlite3.open( dbPath) for row in db:nrows(mySQL) do myDataD[int]={} myDataD[int].name = row.DrugName int = int+1 end db:close() doneDB = true print(int) end reLoadData() local springStart = 0 local needToReload = false -- ------------------------------------------------------------------------ -- -- ------------------------------------------------------------------------ local function scrollListener( event ) local buffer = 50 local phase = event.phase local row = event.target local params = event.target.params if event.phase == "began" and not row.selected then startXpos = event.x startYpos = event.y row.selected = true elseif phase == "ended" or phase == "moved" then row.selected = false if phase == "ended" and event.y \< startYpos + buffer and event.y \> startYpos - buffer and event.x \< startXpos + buffer and event.x \> startXpos - buffer then --native.showAlert("Row " .. row.index, "Selected") if params == nil then print("category") else --print ("Row " .. params.sub .. " Selected " .. params.name) ShowingDoc = true local \_H = 480 local \_W = 320 local SBH = 50 --local doc = string.upper(params.name) local doc = params.name --doc = string.gsub(doc , "%s$", "") doc = "HTML/Drugs/"..doc..".html" print("-") print ("-\> "..doc) SearchTextArea.isVisible = false webView = native.newWebView( 0, SBH, \_W, \_H-SBH ) webView.anchorX = 0 webView.anchorY = 0 webView:request( doc, system.ResourceDirectory) end end end return true end -------------------------------------------------------------------------------------- --ON ROW TOUCH -------------------------------------------------------------------------------------- local function onRowTouch(event) return true end -------------------------------------------------------------------------------------- local function onRowRender( event ) --Set up the localized variables to be passed via the event table local row = event.row local id = row.index local params = event.row.params local idx if ( event.row.params ) then idx = params.idx --row.bg = display.newRect( 0, 0, display.contentWidth, 55 ) row.bg = display.newImageRect( "Hospitalcell.png", display.contentWidth, 55 ) row.bg.anchorX = 0 row.bg.anchorY = 0 --row.bg:setFillColor( 0/255, 84/255, 166/255 ) --row.bg:setStrokeColor( 0/255, 84/255, 166/255 ) row:insert( row.bg ) --row.imgArrow = display.newImageRect( "sidearrow.png", display.contentWidth, 55 ) --row.imgArrow.anchorX = 0 --row.imgArrow.anchorY = 0 --row.imgArrow.x = display.contentWidth - 20 --row.imgArrow.y = 10 row.nameText = display.newText( params.name, 16, 0, native.systemFontBold, 20 ) row.nameText.anchorX = 0 row.nameText.anchorY = 0 row.nameText:setFillColor( 1 ) row.nameText.y = 18 row.nameText.x = 10 row:insert( row.nameText ) row.imgArrow = display.newImageRect( "sidearrow.png", 12, 20 ) row.imgArrow.anchorX = 0 row.imgArrow.anchorY = 0 row.imgArrow.x = display.contentWidth - 20 row.imgArrow.y = 18 row:insert(row.imgArrow) end return true end local myListD = widget.newTableView { top = navBarHeight + 40, width = display.contentWidth, height = display.contentHeight - navBarHeight - tabBarHeight, backgroundColor = {0/255, 82/255, 154/255 }, onRowRender = onRowRender, onRowTouch = onRowTouch, listener = scrollListener } ---------------------------------------------------------- -- Load table function ---------------------------------------------------------- local function loadTableD() --myListD:deleteAllRows() local currentCat = "none" for i = 1, #myDataD do myListD:insertRow{ rowHeight = 55, isCategory = false, rowColor = {0/255, 84/255, 166/255 }, lineColor = { 0/255, 70/255, 130/255 }, params = { name = myDataD[i].name, isCat = false } } end end local function DisplayResults() -- Search text changed -- Get the new data reLoadData() -- Delete rows Reload the table myListD:deleteAllRows() loadTableD() -- Set oldsearch to current search so we can know when it changes OldSearchText = SearchText end --------------------------------------------------------- -- Load Table --------------------------------------------------------- loadTableD() group:insert( myListD ) group.x = display.contentCenterX group.y = display.contentCenterY ------------------------------------------------------ -- -- BACK BUTTON -- ------------------------------------------------------ backBtn:addEventListener( "tap", function( event ) -- Check to see if we're showing a document if (ShowingDoc == false) then -- not showing a document so go to menu SearchTextArea:removeSelf() SearchTextArea = nil storyboard.gotoScene( "scene\_menu" ) else -- showing a document so kill it webView:removeSelf() webView = nil ShowingDoc = false SearchTextArea.isVisible = true end end ) local function SearchTextAreaListener( event ) if ( event.phase == "began" ) then -- user begins editing text field print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted" ) then -- text field loses focus -- do something with defaultField's text print( "Submitted text: " .. event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) SearchText = event.text -- See if it changed if (SearchText ~= OldSearchText) then DisplayResults() end end end -- Create text field SearchTextArea = native.newTextField( 45, 55,220, 36 ) SearchTextArea.anchorX = 0 SearchTextArea.anchorY = 0 SearchTextArea.hasBackground = false SearchTextArea:setTextColor( 1,1,1 ) SearchTextArea:addEventListener( "userInput", SearchTextAreaListener ) --clck:addEventListener( "tap", function( event ) -- Check to see if we're showing a document -- if tapnum == 0 then -- SearchText = "a" -- end -- if tapnum == 1 then -- SearchText = "s" -- end -- if tapnum == 2 then -- SearchText = "" -- end -- tapnum = tapnum + 1 -- if tapnum \>2 then -- tapnum = 0 -- end -- See if it changed -- if (SearchText ~= OldSearchText) then -- DisplayResults() -- end -- end) end -- Called BEFORE scene has moved onscreen: function scene:willEnterScene( event ) local group = self.view end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view end -- Called AFTER scene has finished moving offscreen: function scene:didExitScene( event ) local group = self.view end -- Called prior to the removal of scene's "view" (display view) function scene:destroyScene( event ) local group = self.view end -- Called if/when overlay scene is displayed via storyboard.showOverlay() function scene:overlayBegan( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end -- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay() function scene:overlayEnded( event ) local group = self.view local overlay\_name = event.sceneName -- name of the overlay scene end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "willEnterScene" event is dispatched before scene transition begins scene:addEventListener( "willEnterScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "didExitScene" event is dispatched after scene has finished transitioning out scene:addEventListener( "didExitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) -- "overlayBegan" event is dispatched when an overlay scene is shown scene:addEventListener( "overlayBegan", scene ) -- "overlayEnded" event is dispatched when an overlay scene is hidden/removed scene:addEventListener( "overlayEnded", scene ) --------------------------------------------------------------------------------- return scene

can u send me the full source code because your code seems to be missing something like the image.png file i dont have

Hi, Guys i’m a newbie to corona and lua, I need to know how to trigger an alert window after user select an option from a wheel picker window ?

Welcome to the forum @avinash248668, please create a new thread with your question. This has nothing to do with building a SearchBar sample app. When you ask an unrelated question on an existing thread, it’s called “Hijacking” and it’s not permitted in our forums. We welcome your question, but you need to ask it on an appropriate thread or on its own.

Thanks

Rob

Hi, Guys i’m a newbie to corona and lua, I need to know how to trigger an alert window after user select an option from a wheel picker window ?

Welcome to the forum @avinash248668, please create a new thread with your question. This has nothing to do with building a SearchBar sample app. When you ask an unrelated question on an existing thread, it’s called “Hijacking” and it’s not permitted in our forums. We welcome your question, but you need to ask it on an appropriate thread or on its own.

Thanks

Rob