android格式edittext每4个字符后显示空格

android format edittext to display spaces after every 4 characters(android格式edittext每4个字符后显示空格)
本文介绍了android格式edittext每4个字符后显示空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android - 我想将用户输入的数字输入 EditText - 它需要用空格分隔 - 每 4 个字符.示例:123456781234 -> 1234 5678 1234

这仅用于视觉目的.但是我需要不带空格的字符串以供进一步使用.

我能做到这一点的最简单方法是什么?

解决方案

需要使用TextWatcher 实现视觉目的空间.

并使用任何简单的 按空格分割字符串 逻辑将其加入或循环遍历每个字符的整个字符串,并从字符串中消除 (char) 32p>

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

This is only for visual purpose. However i need the string without spaces for further usage.

What is the easiest way I can do this?

解决方案

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

这篇关于android格式edittext每4个字符后显示空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)