获取已删除的文本
我正在使用 onTextChanged(charSequence s, int start, int before, int count) 并希望获取 Edittext 的已删除文本。我相信你可以通过参数 s 获取它,但我怎么知道文本已被删除而不是添加? (例如 if s.equals("Example")
我如何知道“Example”已从 Edittext 中删除,而不是添加到 Edittext 中?)
I am using onTextChanged(charSequence s, int start, int before, int count)
and would like to get the deleted text of an Edittext. I believe you can get it through the parameter s but how would I know that the text has been deleted not added? (E.g. if s.equals("Example")
how do I know that "Example" was deleted from, not added to, the Edittext?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要从 EditText 中删除文本,则
onTextChanged
的最终参数int lengthAfter
应等于零(您将此参数标记为“count”)。onTextChanged (CharSequence text, int start, int lengthBefore, int lengthAfter)
您还可以考虑使用
TextWatcher
用于更精细的控制。If you're deleting text from an EditText, the final parameter for
onTextChanged
,int lengthAfter
should be equal to zero (you have this parameter labeled 'count').onTextChanged (CharSequence text, int start, int lengthBefore, int lengthAfter)
You could also consider using a
TextWatcher
for finer control.使用 onTextChanged 或 TextWatcher 并不重要,要从这些方法中获取文本并识别它是被删除还是添加,您必须编写自己的逻辑代码,如下所示。
从字符串 1 的 onTextChanged 方法获取文本
从字符串 2 的 EditText 获取文本
转换字符串转换为字符数组。
循环、比较和查找缺失的字符。
我针对你的问题说了这个独特的算法,但没有被问到。
Use onTextChanged or TextWatcher that doesn't matter, to get text from these methods and recognize whether it was deleted or added, you've to write your own code of logic as follows.
Get text from onTextChanged method on String 1
Get text from EditText on String 2
Convert the string to array of characters.
Loop through,compare & find missing characters.
I said this unique Algorithm for your problem which had not been asked.