native text controller

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AstghikM
Posts: 45
Joined: Mon Sep 08, 2014 8:35 pm

native text controller

Post by AstghikM » Mon Sep 28, 2015 11:53 am

Hi everyone :)
i need an idea how to show up android keyboard automatically using native text controller. the problem is that first i have to create the control, then click on it and only after that the keyboard shows up. Here is what i tried using this lesson http://lessons.runrev.com/m/4069/l/2911 ... -on-mobile

Code: Select all

on inputCreate pControll, pControlName, pType

   put pControll into lCurrentFieldID
   put pControlName into lCurrentFieldName
   
   if "testinput" is among the lines of mobileControls() then
      inputDelete
   end if   
   mobileControlCreate "input", pControlName
   mobileControlSet pControlName, "rect", the rect of pControll
   mobileControlSet pControlName, "visible", true
   mobileControlSet pControlName, "alpha", 0
   mobileControlSet pControlName, "contentType", pType
   mobileControlSet pControlName, "text", the text of pControll
 inputFocus
end inputCreate

on inputFocus
   mobileControlDo lCurrentFieldName,"enabled","true" //make sure the input is focus-able
   mobileControlDo lCurrentFieldName, "focus"             //actually focus on the field so the keyboard pops up, etc.
end inputFocus
i called inputCreate in openfield but this didn't work for me, then i tried to call it on openCard to have the controller already created, but as i had more than one field, the keyboard appeared only on the last field.

thanks

Astghik

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: native text controller

Post by MaxV » Tue Sep 29, 2015 1:31 pm

Dear Astghik
for every input that you want to create, you just need:

Code: Select all

on OpenCard
   mobileControlCreate "input", "myCuteControl"
    mobileControlSet "myCuteControl", "rect", the rect of  field "mycutefield"
   mobileControlSet "myCuteControl", "visible", true
end OpenCard
Every native input, clicking on it show the keyboard.
If you call inputCreate, you have to pass 3 parameters: pControll, pControlName, pType. For example:

Code: Select all

inputCreate 1, "mycuteControll", "plain"
or

Code: Select all

inputCreate 1, "mycuteControll", "password"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

AstghikM
Posts: 45
Joined: Mon Sep 08, 2014 8:35 pm

Re: native text controller

Post by AstghikM » Wed Sep 30, 2015 6:16 am

MaxV wrote: Every native input, clicking on it show the keyboard.
If you call inputCreate, you have to pass 3 parameters: pControll, pControlName, pType. For example:

Code: Select all

inputCreate 1, "mycuteControll", "plain"
or

Code: Select all

inputCreate 1, "mycuteControll", "password"

Thank you MaxV,
I tried that and it works

Code: Select all

   
on preOpenCard
   if the environment is "mobile" then
      --- create native text controlers for the text fields
      --- parameters are the long id of object, native controler name, controller type
      inputCreate the long id of field "login" of group "login", the id of field "login" of group "login", "plain"
      inputCreate the long id of field "password" of group "login", the id of field "password" of group "login", "password"
   end if
end preOpenCard

on inputCreate pControll, pID, pType
 
   if "testinput" is among the lines of mobileControls() then
      inputDelete
   end if   
   mobileControlCreate "input", "control" & pID
   mobileControlSet "control" & pID, "rect", the rect of pControll
   mobileControlSet "control" & pID, "visible", true
   mobileControlSet "control" & pID, "alpha", 0
   mobileControlSet "control" & pID, "hIndicator", false
   mobileControlSet "control" & pID, "vIndicator", false
   mobileControlSet "control" & pID, "contentType", pType
   mobileControlSet "control" & pID, "text", the text of pControll
end inputCreate

But for now i have another problem in inputReturnKey in this function i would put the text into LC field but the code is braking right after replace, so not doing the placement. Any idea why it happens? i am testing it on android phone.

Code: Select all

on inputReturnKey
   put mobileControltarget () into tControllerName
   put mobileControlGet(tControllerName, "text") into tControlText
  
   put tControllerName into tFieldID

   --- get the field id which is in the controller name we created
   replace "control" with empty in tFieldID
   
   put tControlText into field ID tFieldID
 
end inputReturnKey

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: native text controller

Post by MaxV » Wed Sep 30, 2015 3:08 pm

the line

Code: Select all

   put mobileControltarget () into tControllerName
is not correct. mobileControltarget () function needs 2 parameters
tControllerName is not defined, is it a global variable? What does it contains?
You code seems to me to use tControllerName as a variable containing something like "control 3".
Check what tControllerName contains or use custom properties instead.

Livecode contains a PDF of 378 pages, go to Help -> User Guide, here you'll learn a lot about livecode.

However this code, if tControllerName is a global variable containing "control 1" (or any other number) should work:

Code: Select all

on inputReturnKey
   put mobileControlGet(tControllerName, "text") into tControlText 
   put tControllerName into tFieldID
   --- get the field id which is in the controller name we created
   replace "control" with empty in tFieldID   
   put tControlText into field ID tFieldID
end inputReturnKey
Remeber to don't use global variables in your code: http://newsletters.livecode.com/may/iss ... etter3.php
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply