android format edittext to display spaces after every 4 characters

前端 未结 12 1686
傲寒
傲寒 2020-12-10 13:27

Android - I want to get a number input from the user into an EditText - it needs to be separated by spaces - every 4 characters. Example: 123456781234 -> 1234 5678 1234

12条回答
  •  伪装坚强ぢ
    2020-12-10 13:55

    You need to use TextWatcher to achieve visual purpose spaces.

    And use any simply split string by space logic to join it back or loop through the entire string per character wise and eliminate (char) 32 from the string

提交回复
热议问题