Sha*_*zon 10 android textwatcher
我必须做一些明显的事情,但我无法弄清楚它是什么.我只是想在可编辑中插入一个字符:
@Override
public void afterTextChanged(Editable s) {
Log.d(TAG, "inserting space at " + location);
s.insert(location, " ");
Log.d(TAG, "new word: '" + s + "'");
}
Run Code Online (Sandbox Code Playgroud)
但是永远不会改变.字符串's'足够长,因为我打印它看起来很好.如果我调用Editable.clear(),它将被清除,我可以用Editable.replace()替换多个字符.想法?
Bec*_*caP 13
要使用输入过滤器编辑可编辑的内容,只需保存当前过滤器,清除它们,编辑文本,然后还原过滤器.
以下是一些适合我的示例代码:
@Override
public void afterTextChanged(Editable s) {
InputFilter[] filters = s.getFilters(); // save filters
s.setFilters(new InputFilter[] {}); // clear filters
s.insert(location, " "); // edit text
s.setFilters(filters); // restore filters
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2531 次 |
| 最近记录: |