Robmiracle
Thank you for your response. I have been playing around with the code but still have some holes. I answered some of your questions below.
What is supposed to happen when a number is entered? They call fieldHandler which all it does is dismiss the keyboard. What should go on there?
I want the person to enter a number in the numberFieldTwo and numberFieldThree then it automatically show the result in numberFieldFour or a space where numberFieldFour is located. I guess I just need regular box there?
What is the 3rd input field for? You just need to input 2 numbers then “display” the results.
Yes you are correct. I don’t need a box there, I just need to display the results.
Where/When do you tell the app to perform the subtraction? Do you want it to automatically show the result after each number is input, or do you want a button that is pressed to generate the result?
I want it to automatically show the results in the box located where numberFieldFour is at right now.
what calls onnumberTwo and onnumberThree events?
I don’t understand this question.
Current Code
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local physics = require (“physics”)
physics.start ()
local ui = require(“ui”)
local tHeight – forward reference
local background = display.newImage (“blackbackground.png”)
background.x = 240
localGroup:insert(background)
–> This sets the background
local screen6 = display.newImage (“screen6.png”)
screen6.x = 240
localGroup:insert(screen6)
–> This sets Screen6
– General event handler for fields
– You could also assign different handlers for each textfield
local function fieldHandler( event )
if ( “began” == event.phase ) then
– This is the “keyboard has appeared” event
– In some cases you may want to adjust the interface when the keyboard appears.
elseif ( “ended” == event.phase ) then
– This event is called when the user stops editing a field: for example, when they touch a different field
elseif ( “submitted” == event.phase ) then
– This event occurs when the user presses the “return” key (if available) on the onscreen keyboard
– Hide keyboard
native.setKeyboardFocus( nil )
end
end
– Predefine local objects for use later
local numberField, numberFieldTwo, numberFieldThree, numberFieldFour, difference
local fields = display.newGroup()
– Create a Background touch event
– Tapping screen dismisses the keyboard
– Needed for the Number textField since there is
– no return key to clear focus.
local listener = function( event )
– Hide keyboard
print(“tap pressed”)
native.setKeyboardFocus( nil )
end
– Determine if running on Corona Simulator
local isSimulator = “simulator” == system.getInfo(“environment”)
– Native Text Fields not supported on Simulator
if isSimulator then
msg = display.newText( “Native Text Fields not supported on Simulator!”, 0, 280, “Verdana-Bold”, 12 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,0 )
end
– Add listener to background for user “tap”
screen6:addEventListener( “tap”, listener )
local house = display.newImage (“house.png”)
house.x = 45
house.y = 35
house.xScale = .5
house.yScale = .5
localGroup:insert(house)
–>This places the House
local function touchedHouse (event)
if (“ended” == event.phase) then
director:changeScene (“titlescreen”)
media.playEventSound( “click_x.caf” )
end
end
house:addEventListener (“touch”, touchedHouse)
– Handlers for login dialog UI
local function onnumberTwo( event )
if ( “began” == event.phase ) then
– Note: this is the “keyboard appearing” event
– In some cases you may want to adjust the interface while the keyboard is open.
elseif ( “ended” == event.phase ) then
– Automatically tab to numberFieldThree if user taps screen (convenient!)
native.setKeyboardFocus( numberFieldThree )
end
end
local function onnumberThree( event )
– Hide keyboard when the user taps the screen
if ( “ended” == event.phase ) then
native.setKeyboardFocus( nil )
end
end
local smallbrain = display.newImage (“smallbrain.png”)
smallbrain.x = 428
smallbrain.y = 280
smallbrain.xScale = .5
smallbrain.yScale = .5
localGroup:insert(smallbrain)
–>This places the brain
local function touchedSmallbrain (event)
if (“ended” == event.phase) then
director:changeScene (“screen7a”)
media.playEventSound( “click_x.caf” )
end
end
smallbrain:addEventListener (“touch”, touchedSmallbrain)
local backbutton = display.newImage (“backbutton.png”)
backbutton.x = 60
backbutton.y = 280
backbutton.xScale = .4
backbutton.yScale = .4
localGroup:insert(backbutton)
local function touchedBackbutton (event)
if (“ended” == event.phase) then
director:changeScene (“screen5”)
media.playEventSound( “click_x.caf” )
end
end
backbutton:addEventListener (“touch”, touchedBackbutton)
–>This places the backbutton
– *** Create native input textfields ***
– Note: currently this feature works in device builds or Xcode simulator builds only
– Note: currently this feature works in device builds only
local isAndroid = “Android” == system.getInfo(“platformName”)
local inputFontSize = 30
local inputFontHeight = 30
tHeight = 50
if isAndroid then
– Android text fields have more chrome. It’s either make them bigger, or make the font smaller.
– We’ll do both
inputFontSize = 30
inputFontHeight = 30
tHeight = 50
end
numberFieldTwo = native.newTextField( 180, 125, 120, tHeight, fieldHandler )
numberFieldTwo.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldTwo.inputType = “number”
numberFieldThree = native.newTextField( 180, 180, 120, tHeight, fieldHandler )
numberFieldThree.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldThree.inputType = “number”
numberFieldFour = native.newTextField( 180, 245, 120, tHeight, fieldHandler )
numberFieldFour.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldFour.inputType = “number”
– Add fields to our new group
fields:insert(numberFieldTwo)
fields:insert(numberFieldThree)
fields:insert(numberFieldFour)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua] [import]uid: 72372 topic_id: 13109 reply_id: 49482[/import]