1

I'm looking for a simple way for Android, when a user taps a in a edit text box, it will add a hyphen inbetween the number set. Sort of like a phone number, but will be set in a custom position.

For example Book number 05, CD number 15, track number5 = 0515-5. So when they start typing, the app will automatically enter the hyphen.

Should I use some type of listener and count how many characters are entered, then when it hits that number of characters, it will add the hyphen?

Thanks!

Anthony Honciano
  • 1,683
  • 5
  • 24
  • 30

1 Answers1

1

Use an InputFilter.

See my answers here: press "." many times (validate ip address in EditText while typing) and here: How to set Edittext view allow only two numeric values and two decimal values like ##.## for ideas on how to implement it

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108