如何为EditText上preference Android中只设置数值? [英] how to set only numeric value for EditTextPreference in android?

查看:621
本文介绍了如何为EditText上preference Android中只设置数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为EditText上preference Android中只设定数值。 我希望用户输入端口号不知道我怎么可以把限制有

我用这code,用户可以输入任意字符串。要限制用户ATLEAST数字仅

 < EditText上preference
    安卓:设置defaultValue =4444
    机器人:关键=端口
    机器人:标题=端口
    机器人:依赖=service_on
    />
 

解决方案

的EditText preference部件应采取相同的属性作为一个普通的EditText,所以使用:

 安卓inputType =数字
 

how to set only numeric value for EditTextPreference in android. I want a user to enter a port number not sure how can I put the limitation there

I am using this code, user can enter any string. Want to limit the user to atleast numbers only

   <EditTextPreference 
    android:defaultValue="4444" 
    android:key="port" 
    android:title="Port" 
    android:dependency="service_on"        
    />    

解决方案

EditTextPreference widgets should take the same attributes as a regular EditText, so use:

android:inputType="number"

这篇关于如何为EditText上preference Android中只设置数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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