在的EditText谷歌Android [英] EditText in Google Android

查看:125
本文介绍了在的EditText谷歌Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建的EditText 允许的数字值 逗号删除和其他值都忽视

I want to create the EditText which allow Numeric Values, Comma and Delete and other values are ignore.

所以,我如何通过编程code实现这一目标?

So How I can achieve this by programming code ?

感谢。

推荐答案

我使用follwing code ++实现同样的事情,希望大家也能从中找到帮助。

I achieved same thing using follwing code, hope you will also find help from it.

editText.addTextChangedListener(controller);


@Override
public void afterTextChanged(Editable s) {
    if(s.trim.length() > 0)
            {
                 int start = s.toString().length() - 1;
                 int a = (int) s.charAt(start);
                 if (!(a >= 48 && a <= 57 || a == 44))
                    s = s.delete(start, start + 1);
            }
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

这篇关于在的EditText谷歌Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆