How to do combo box like in Corona sdk?

Also I am not able to control the height and the width of the Picker wheel… is there a way to do it ?

regards

Abdul

technically the pickerWheel is a special mode tableView. It might be possible to simulate a comboBox in some cases with a tableView and get better results as the tableView has more controls over visuals etc. Just a thought.

Also checkout Atanas’s newEditField widget. It has a special mode where it bonds with a pickerWheel and hence providing the comboBox feel with the display for chosen item built right into it. Just a thought.

You can not change width or height on the picker wheel unfortunately.

I can’t really give you the code for this as there would be quite a lot of it due the need to setup the picker wheel you can check how in the docs http://docs.coronalabs.com/api/library/widget/newPickerWheel.html

The logic of what I meant was this:

 - put text (with optional image background and arrow indicating possible selection popup) on screen for the first and second combo.

 - when the user presses the first text popup the picker wheel in an overly scene or just draw it over the current scene but make sure you block touches to the objects in the back.

 - when user chooses the value in the first picker you remember it and remove the picker wheel and update the text (if needed) in the second one.

 - when the user presses the second one you popup a picker wheel with possible values based on what was selected in the first one.

When you have some code together and get the picker wheel working if you still have a problem post it here and I’ll look at it.

ksan,

where i can find the docs about the usage of newEditField widget?

Thanks

Abdul

hi primoz,

i am working to try your logic. i am almost there … i will post once done. thanks for the explanation, 

regards

Abdul

We are working on a site to host the newEditField and other widget related goodies from Atanas. It is still in development so not formally announced yet. You can find this site at http://widgetstown.com/ and register for free access to the docs and sample apps. Also checkout the blog section where Atanas and I documented some aspects of the widget and using them through bypassing the versions that are baked into core Corona SDK. Please feel free to leave feedback. 

Thanks ksan for the info , i am trying it and see how to use it :slight_smile:

Abdul

pm me with your email address so we can get you the sample app. Hopefully reviewing the sample will help you overcome this initial challenge. 

Hi All,

I get this working to some extend (not perfect ) and I would like to share with you. Maybe someone needs something to start with   :slight_smile: :

main.lua 

[lua]

local storyboard = require “storyboard”

local options =

{

    effect = “slideLeft”,

    time = 800,

    

}

storyboard.gotoScene( “list”, options )

[/lua]

list.lua

[lua]

local widget = require( “widget” )

local storyboard = require( “storyboard” )

–require (“widgetLibrary.widgetext”)

–require (“widgets.storyboardext”)

display.setDefault( “anchorX”, 0.5 )

display.setDefault( “anchorY”, 0 )

local scene = storyboard.newScene()

local pickerRegions

local pickerSchools

local schoolsTable

local columnData2

local ShowRegion

local showSchool 

local clickBtn     

local RegionImg

local SchoolImg

local whichTextFeild 

local currentTbl

local regionsIsBlank = true

_G.Reg=“Muscat”


function ShowRegion(event)

    pickerRegions.isVisible = true

    pickerSchools.isVisible = false

    whichTextFeild = “Region”

    print(whichTextFeild)

    

end


function UpdateSchool()

    pickerSchools:removeSelf()

    pickerSchools= nil

    

    columnData2 = 

            {

       

                { 

            

                    align = “center”,

                    --width=100,

                    startIndex = 3,

                    labels =currentTbl

                },

                

            }

    pickerSchools = widget.newPickerWheel

        {

                top = 140,

            left = 0,

            columns = columnData2

        }

                

    pickerSchools.isVisible = false

    

    

end


function showSchool(event)

    

    if (regionsIsBlank==true) then

        native.showAlert ( “Note”, “Please select a region first !”  )

    else    

        pickerRegions.isVisible = false

        pickerSchools.isVisible = true

        whichTextFeild = “School”

        print(whichTextFeild)

        print("selectedRegion.text in showSchool = " , selectedRegion.text)

        print("_G.Reg in showSchool = ", _G.Reg)

    end

end


local function handleButtonEvent( event )

            

            if ( _G.Reg == nil ) and (pickerRegions.isVisible ==false) then

                native.showAlert ( “Note”, “Please select a region first !”  )

            else

                    print("whichTextFeild in handlebuttonEvent = " …whichTextFeild)

                    --pickerRegions.isVisible = true

                    if (pickerRegions.isVisible) then

                        

                        local values = pickerRegions:getValues()

                        print(values[1].value)

                        _G.Reg = values[1].value

                        regionsIsBlank=false

                        selectedRegion.text = _G.Reg 

                        currentTbl = schoolsTable[_G.Reg]

                        selectedSchool.text = “”

                        UpdateSchool()

                        pickerRegions.isVisible = false

                     else

                      

                        local values = pickerSchools:getValues()

                        print(values[1].value)

                        _G.School= values[1].value

                        selectedSchool.text = _G.School

                        print(" iam in else")

                        pickerSchools.isVisible = false    

                    end

                    

                    

            end

end

         


function scene:createScene( event )

        local group = self.view

        

        local editGroup = display.newGroup()

        group:insert(editGroup)

        

        print(“i am in create scene : list”)

        – Create the widget

        

        local bg = display.newRect( group, 0, 0, 380, 560)

        bg.anchorX =0

        bg.anchorY =0

        bg:setFillColor(0.5,0.5, 0.5)

        local labelRegion = display.newText( "Region ", 40,55 , native.systemFont, 18 )

         selectedRegion =native.newTextField( 160, 80, 300, 40 )

        

        --selectedRegion = display.newText( “”, 220,200 , native.systemFont, 18 )

        

        local labelSchool = display.newText(  "School ", 40, 120, native.systemFont, 18 )

        selectedSchool= native.newTextField( 160, 145, 300, 40 )

        

         ------------------------

         local columnData = 

            {

                – regions

                { 

                    align = “right”,

                    width = 150,

                    startIndex = 3,

                    labels = {“Muscat”,“AlBatenah”,“Musandam”,“AlDakhlia”,“AlDhahera”},

                },

               

            }

            

            – Create the widget

            pickerRegions = widget.newPickerWheel

            {

                top = 140,

                left= 0,

                columns = columnData

            }

            pickerRegions.isVisible = false

         --------------

         

         local button1 = widget.newButton

            {

                top= 190,

                left=10,

                width = 173,

                height = 39,

                defaultFile = “default.png”,

                overFile = “over.png”,

                --label = “button”,

                onPress = handleButtonEvent

            }

            

            – Change the button’s label text

            --button1:setLabel( “2-Image” )

        -----------------------------------------------------------------------------

        –      CREATE display objects and add them to ‘group’ here.

        –      Example use-case: Restore ‘group’ from previously saved state.

        -------------------------

        schoolsTable= {

            

            Muscat = {“AlFatooq”,“AlHawari”,“Muscat1”,“Omani2”},

            AlBatenah = {“B1”,“B2”,“B3”,“B3”},

            Musandam = {“M1”,“M2”,“M3”,“M3”},

            AlDakhlia = {“K1”,“K2”,“K3”,“K3”},

            AlDhahera = {“D1”,“D2”,“D3”,“D3”}

            

            }

        currentTbl = schoolsTable[_G.Reg]    

        columnData2 = 

            {

       

                { 

            

                    align = “center”,

                    --width=100,

                    startIndex = 3,

                    labels =currentTbl

                },

                

            }

            

            pickerSchools = widget.newPickerWheel

                {

                        top = 140,

                    left = 0,

                    columns = columnData2

                }

                

            pickerSchools.isVisible = false

        

        -----------------------------------------------------------------------------

        group:insert(bg)

        group:insert(labelRegion)

        group:insert(labelSchool)

        --group:insert(clickBtn)

    –    group:insert(RegionImg)

        --group:insert(SchoolImg)

        

end

function scene:enterScene( event )

        local group = self.view

        --clickBtn:addEventListener ( “tap”, ShowPicker )

        print(“i am in enter scene : list”)

        --RegionImg:addEventListener ( “tap”, ShowRegion )

        --SchoolImg:addEventListener ( “tap”, showSchool )

        

        

        

        selectedRegion:addEventListener ( “userInput”, ShowRegion )

        selectedSchool:addEventListener ( “userInput”, showSchool )

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. start timers, load audio, start listeners, etc.)

        -----------------------------------------------------------------------------

end

function scene:exitScene( event )

        local group = self.view

        print(“i am in exit scene : list”)

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)

        -----------------------------------------------------------------------------

end

function scene:destroyScene( event )

        local group = self.view

        -----------------------------------------------------------------------------

        –      INSERT code here (e.g. remove listeners, widgets, save state, etc.)

        -----------------------------------------------------------------------------

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene

[/lua]

only you need images for the button and you will be ready to go… Also I am testing the neweditfield and if i get something useful, i will share with you.

Thanks All for the support.

Abdul