Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对与接口相关的方法有疑问TextWatcher。
TextWatcher
在这种方法中public void onTextChanged(CharSequence s, int Start, int before, int count),为什么CharSequene我们在处理数字时使用 ex:在 EditText 框中,我将输入数字而不是字符。
public void onTextChanged(CharSequence s, int Start, int before, int count)
CharSequene
另外,还有其他方法可以使用吗?
为什么我们在处理数字时使用 CharSequene
此方法不仅限于只接受数字的 EditText,TextWatchers 将返回任何 EditText 的内容。您可以编写自己的方法来仅预测数字,但这可能比将 EditText 限制为仅数字并尝试Integer.valueOf(s)(Float或其他)并捕获任何异常要慢。
Integer.valueOf(s)
Float
有两种从 EditText 获取文本getText()和使用 TextWatcher 的基本方法。没有仅处理数字的内置方法。
getText()