安卓展开的EditText的inputType下? [英] Android: Expand the inputType of EditText?

查看:178
本文介绍了安卓展开的EditText的inputType下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许0-9可能的输入,或 - 的EditText上,无法找到答案

我知道使用|作为一个分离器是可能的:

 的android:inputType下=号|文

但我怎么可以存档这样的事情(太糟糕了它不工作):

 的android:inputType下=号|,|  - 

有谁知道?

问候,

科迪


除了下面的注释:


  

私有类MyKeylistener扩展
  NumberKeyListener {

 公众诠释getInputType(){
      返回InputType.TYPE_CLASS_NUMBER;
    }
    @覆盖
    受保护的char [] getAcceptedChars(){
      返回新的char [] {'0','1','2','3','4','5','6','7','8','9',',', ' - '};
    }


  
  

}



解决方案

我不认为有提供这样一个任意过滤器的方法。你必须使用所提供的滤波器类型的。

如果你不能找到这些类型的组合,你想要什么,你可能需要做用的 TextWatcher 输入过滤上的EditText。

I'd like to allow possible inputs of 0-9, "," or "-" for EditText and couldn't find an answer.

I know using the "|" as an separator is possible:

android:inputType="number|text"

But how can I archive something like this (too bad it doesn't work):

android:inputType="number|,|-"

Does anyone know?

Regards,

cody


Addition to the comment below:

private class MyKeylistener extends NumberKeyListener {

    public int getInputType() {
      return InputType.TYPE_CLASS_NUMBER;
    }
    @Override
    protected char[] getAcceptedChars() {
      return new char[] {'0','1','2','3','4','5','6','7','8','9',',','-'};
    }

}

解决方案

I don't think there is a way to provide an arbitrary filter like that. You have to use the provided filter types.

If you can't find a combination of those types that does what you want, you probably need to do the filtering yourself using a TextWatcher or InputFilter on the EditText.

这篇关于安卓展开的EditText的inputType下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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