Android app first field already has focus but no onscreen kb

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
gaanthony
Posts: 2
Joined: Sun May 01, 2016 2:35 am

Android app first field already has focus but no onscreen kb

Post by gaanthony » Sun May 01, 2016 3:11 am

Issue: In the BMI Calculator app from the getting started tutorial when it launches on my Samsung S7 Edge physical device, the first field has the focus but the keyboard is not displayed. If I tap the field nothing happens. If I tap the next field the keyboard comes up and I can enter text/numbers and then select the first field and the keyboard stays and I can then perform input.
I'm trying to figure out how not to have the app have focus on any field on the stack until the user physically selects the field at which time the keyboard would be displayed for input. At least that is what I think I want to accomplish.
Any pointers appreciated.

About me:
I'm completely new to LiveCode and have been learning about it via the BMI Calculator tutorial and reading through the documentation resources, LC dictionary and forum. I'm testing out the latest LC 8 RC1. With the outdated documentation I figured out how to install Android Studio 2.1 and download the Android 4.0.3 SDK and libraries supported by LC 8 RC1, then build the BMI app and fill out the settings for an Android standalone app and create it and install and run it successfully on my physical device. Whew! What an accomplishment it seems! :lol:

AxWald
Posts: 368
Joined: Thu Mar 06, 2014 2:57 pm

Re: Android app first field already has focus but no onscree

Post by AxWald » Sun May 01, 2016 12:49 pm

Hi,

quick & dirty:
Make another field (may be 1x1 pixel) that gets the focus when going to this card?
Before the one you want to type in?

Have fun!
Livecode programming until the cat hits the fan ...

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Android app first field already has focus but no onscree

Post by dave.kilroy » Sun May 01, 2016 3:26 pm

Hi @gaanthony and welcome to the forum! Yes this can be an irritating behaviour on mobile devices and there are several ways to manage it (Axwald has already shown you one).

My own preference is to manage the 'traversalOn' property of the field or fields in question. This means that whilst the card is opening no message is sent to trigger the on-screen keyboard, and by the time a user wants to enter some text the field (and on-screen keyboard) is ready and waiting...

Code: Select all

on preOpenCard
  setTraversalOff
end preOpenCard

on openCard
  send setTraversalOn to me in 750 milliseconds
end openCard

on setTraversalOff
  set the traversalOn of fld "fldTextEntry" to false
end setTraversalOff

on setTraversalOn
  set the traversalOn of fld "fldTextEntry" to true
end setTraversalOn
But that is just my way (I don't really fancy the idea of dummy fields), others here will have their own favourite way of doing things...
"...this is not the code you are looking for..."

gaanthony
Posts: 2
Joined: Sun May 01, 2016 2:35 am

Re: Android app first field already has focus but no onscree

Post by gaanthony » Sun May 01, 2016 7:43 pm

Great. Thank you both for the pointers.

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Android app first field already has focus but no onscreen kb

Post by jim1001 » Tue May 01, 2018 1:19 pm

Dave Kilroy - have you used your traversalOn method for native android controls such as a multiline input field created by

Code: Select all

mobileControlCreate "multiline", "myMultiLineTextInput"
The dictionary doesn't say this property can be set for native android controls as far as I can see...

Thanks.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Android app first field already has focus but no onscreen kb

Post by dave.kilroy » Tue May 01, 2018 1:33 pm

Hi @jim1001 - yep it works for Android for single line inputs, however have never tried multi-line so can't confirm that (should think it would be the same as single line?)

EDIT: replied too quick, had a look at code I actually use-

Code: Select all

on openCard
   if isMobile() then 
      send setTraversalOn to me in 500 millisecs
      send "inputCreate ncFirstName" to me in 650 millisecs
      send "inputCreate ncLastName" to me in 700 millisecs
   end if
end openCard
So my handler setTraversalOn sets the traversalOn of my ordinary LiveCode fields to true (I also have LiveCode fields for when the app is used by desktops - what I should probably do is to create relevant controls depending on the platform - but it works...)


SECOND EDIT: and my 'inputCreate' handler creates mobile input controls...
"...this is not the code you are looking for..."

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Android app first field already has focus but no onscreen kb

Post by jim1001 » Tue May 01, 2018 7:05 pm

Dave,

Many thanks for replying.
So my handler setTraversalOn sets the traversalOn of my ordinary LiveCode fields to true
OK - so what is your code to set traversalOn for Android native mobile fields? I thought you had to use mobileControlSet for them, no?

At the moment I can't even focus on the Android native mobile field when the card opens. My code is
on openCard
focus on nothing
mobileControlDo "nativeInputField", "focus"
end openCard
but the flashing cursor appears in another field when the card opens.

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Android app first field already has focus but no onscreen kb

Post by dave.kilroy » Wed May 02, 2018 12:58 pm

hi @jim1001- no the traversalOn stuff is only for LiveCode fields, native fields don't use that property. If you've got a keyboard appearing it sounds like you have a field somewhere on your card (maybe off screen) that has it's traversalOn property set...

Search it down and nuke (or manage) that setting!

Kind regards

Dave

EDIT: other properties of fields to check are: lockText, autoHilite
"...this is not the code you are looking for..."

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Android app first field already has focus but no onscreen kb

Post by jim1001 » Wed May 02, 2018 2:49 pm

Dave, Thanks for latest reply. My wish is for the card to open with the native Android input field in focus and the keyboard visible. I can't make that happen at the moment. Not a major issue though - once the user clicks in the input field the keyboard appears as expected (& desired). I may have more of a play around...

All the best, Jim

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: Android app first field already has focus but no onscreen kb

Post by dave.kilroy » Wed May 02, 2018 2:59 pm

Oh I see - try something like

Code: Select all

mobileControlDo "myTextInput","focus" 
However, depending on whether you are using any visual effects when entering your card (such as "push right") you'll probably want to delay when the keyboard appears slightly to let the visual effect finish - which you can do by sending commands 'in time'
"...this is not the code you are looking for..."

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”