以编程方式更改android:digits [英] Change android:digits programmatically

查看:317
本文介绍了以编程方式更改android:digits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在布局xml中有这个

I have this in the layout xml

android:digits="0123456789."
android:inputType="phone" />

我想要的是能够以编程方式更改它,并能够来回更改它. inputType部分可以配合使用

What I want is to be able to change it programatically and be able to change it back and forth. The inputType part is fine with

manual_ip.setInputType(InputType.TYPE_CLASS_TEXT);

manual_ip.setInputType(InputType.TYPE_CLASS_PHONE);

但是我对数字部分一无所知. 我需要将字符数限制为"0123456789".或根据复选框状态允许所有操作.

But I'm clueless with digits parts.. I need to limit the chars to "0123456789." or allow everything depending on a checkbox state.

推荐答案

添加

manual_ip.setKeyListener(DigitsKeyListener.getInstance("0123456789."));

之后

manual_ip.setInputType(InputType.TYPE_CLASS_PHONE);

之后没有任何内容

manual_ip.setInputType(InputType.TYPE_CLASS_TEXT);

解决了我的问题!

这篇关于以编程方式更改android:digits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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