Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding extra listeners  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the best way to add extra listeners depending on what was previously typed?
To clarify : if I type '*' I want to listen for a second key (a numeric key) before deciding what to do. '*1', '*2' and '*3' will each perform diiferent functions. However, '1', '2' and '3' on their own perform totally separate functions.
Is there a good tried and tested way to do this sort of thing in Java? I can think of one or two ways but I'd like to hear some other suggestions.
Thanks.
Paul
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
I am not really sure you can remove and add listeners and expect some control over it. IMOP, you will have to place the smarts inside your single KeyListener. The code below shows one way of doing what you are asking. Every time that a bad set is received the KeyListener starts over.

Enjoy,
Manfred.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manfred.
This is one of the ways I had in mind to do this. It's not ideal but I'm going to give it a shot.
Thanks.
Paul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!