• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Request Focus for EditText

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am using two different EditText for number input from the user. I am using “requestFocus” to switch between them.

When typing in the second EditText(minutes), I don’t want “requestFocus” to switch to hours directly when “length()==00”.
I want the switch to happen only when “length()==00” AND backspace is pressed. (As shown in image 4 below)






Here’s the solution I tried that don’t seem to work.

First I created a Boolean variable and set it to false:



I got an “setOnkeylisterner” that should change the value of “backSpace” to true when it is pressed AND when the minutes text field is empty  


Then in EditText for the minutes I got an TextWatcher that “requestFocus” only when min.length = 0 AND “backspace = true”.



Also when then entering a number in the text field for hours, “backSpace” is set to false again:



Before i tried with this solution(backSpace  and a java method "onKey" to track backspace), the EditText would change focus directly to hours. Like from image 2-4.
Now it only stays in the EditText for minutes no matter how many backspaces is being pressed so the problem might be with the tracking of the backspace key or something.

Any ideas on how I can implement the behavior I am looking for?
 
Daniel Andersson
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After doing some research on this topic it seems like android can't detect backspace press from the onscreen keyboard :O
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!