XGo*_*het 10 android android-edittext
我正在使用android.text.TextWatcher接口来侦听我的一个应用程序中的EditText上的更改.我使用beforeTextChanged()和onTextChanged()监视更改以允许撤消选项.
通常,更改一次发生一个字符,例如,如果用户键入"hello",我将获得beforeTextChanged()方法的start,after和count值的以下值:
start = 0; count = 0; after = 1; // typed 'h'
start = 1; count = 0; after = 1; // typed 'e'
start = 2; count = 0; after = 1; // typed 'l'
start = 3; count = 0; after = 1; // typed 'l'
start = 4; count = 0; after = 1; // typed 'o'
Run Code Online (Sandbox Code Playgroud)
现在,在ICS /三星Galaxy Nexus上,拼写建议处于活动状态,当我输入相同的文本时,EditText中的单词加下划线,直到我插入一个空格,我得到以下结果:
start = 0; count = 0; after = 1; // typed 'h'
start = 0; count = 1; after = 2; // typed 'e'
start = 0; count = 2; after = 3; // typed 'l'
start = 0; count = 3; after = 4; // typed 'l'
start = 0; count = 4; after = 5; // typed 'o'
Run Code Online (Sandbox Code Playgroud)
根据文档,后一种行为被视为"用户键入一个1个字母的单词,然后将其删除并键入2个字母的单词,然后将其删除并键入3个字母的单词,依此类推......".当我在EditText上执行undos时,我得到"hello","","hell","","hel","","he","","h",我只想拥有"你好", "".
有没有办法阻止拼写建议给出这些值.恕我直言,这打破了方法文档中给出的合同.
如果没有,有没有办法阻止我的编辑文本的建议?
您可以轻松地阻止建议:
<EditText
...
android:inputType="textNoSuggestions" />
Run Code Online (Sandbox Code Playgroud)
我相信这适用于所有ICS设备.我认为旧设备上没有该字段,但在不应该出现问题的情况下.