android设置4个字符,android format edittext在每4个字符后显示空格(android format edittext to display spaces after eve...

android format edittext在每4个字符后显示空格(android format edittext to display spaces after every 4 characters)

Android - 我想从用户获取一个数字输入到EditText中 - 它需要用空格分隔 - 每4个字符。 例如:123456781234 - > 1234 5678 1234

这仅用于视觉目的。 但是,我需要没有空间的字符串作进一步的使用。

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

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?

原文:https://stackoverflow.com/questions/10252757

更新时间:2019-11-02 15:03

最满意答案

您需要使用TextWatcher来实现可视目的空间。

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

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

2012-04-20

相关问答

我为一个项目编写了这个TextWatcher ,希望对某个人有帮助。 请注意,它不会验证用户输入的日期,并且您应该在焦点更改时处理该问题,因为用户可能尚未完成输入日期。 更新25/06使它成为维基,以查看我们是否达到更好的最终代码。 07/06更新我最终为观察者本身添加了一些验证。 它将使用无效日期执行以下操作: 如果月份大于12,则将为12(12月) 如果日期大于所选月份的日期,则将其作为该月份的最大值。 如果年份不在1900-2100范围内,请将其更改为范围内 这个验证符合我的需求,但是你们中

...

您需要使用TextWatcher来实现可视目的空间。 并且使用任何简单的空格逻辑拆分字符串将其加回或循环遍历每个字符的整个字符串,并从字符串中消除(char) 32 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 chara

...

试试这个.. trim() 从字符串的开头和结尾删除空白字符。 getText().toString().trim();

Try this.. trim() To Remove white space characters from the beginning and end of the string. getText().toString().trim();

使用具有必要音乐PNG位图的SurfaceView。 您可以在这里找到许多所需的位图,假设您的项目可以处理任何开放源代码许可的Wikibooks使用。 如果不行,我相信你可以在其他地方找到音乐位图。 Use a SurfaceView with the necessary music PNG bitmaps. You can find a lot of the needed bitmaps here, assuming your project can handle whatever open s

...

我认为你不需要使用edittext来实现它。 您可以添加水平线性布局,其中布局中不包含任何视图。 而且您可以创建一个布局,该布局将作为视图填充在水平线性布局中。 (那个名字可以是row_word)这个布局将包括每个edittext下面的下划线。 您可以使用linearlayout来实现它。 在您的片段中,您可以编写一个填充方法,如下所示: public class Character

{

public String char;

public boolean isFilled;

...

您可以使用DecimalFormat public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {

// TODO Auto-generated method stub

DecimalFormat df = new DecimalFormat("$###,###");

String value = df.format(arg1);

System.out.println(value);

...

看来你没有调用updateStandard() 。 你为什么不试试这个: @Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main2);

totalcostEdit = (EditText) findViewById (R.id.totaltripcostseditText)

...

我可以想到两种方法来实现它: 使用addTextChangedListener : yourEditText.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {

// Do your tricks here

}

public void beforeTextChanged(CharSequ

...

请用这个 public class CustomFormatWatcher implements TextWatcher {

private int size;

public CustomFormatWatcher(int size) {

this.size = size;

}

@Override

public void beforeTextChanged(CharSequence charSequence, int i, int i1

...

EditText content = (EditText) layout.findViewById(R.id.txt_content);

int startSelection = content.getSelectionStart();

int endSelection = content.getSelectionEnd();

// important. dont use getText()

Spannable sb = new SpannableString( content.toS

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值