具有固定后缀的 Android EditText

标签 android android-edittext

我需要一个带有固定后缀的 EditText。我正在使用 TextWatcher 来捕获 onTextChanged 事件,但是如果我通过添加后缀再次更改文本,它会导致由无限递归引起的 stackoverflow 异常。


 msgtextview.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {

               //Doing some other stuff

               msgtextview.setText("Changed Text") //This cause infinite recursion

            }               
        }

这是代码。

最佳答案

我假设您有堆栈溢出,因为当您以编程方式添加后缀时,它会触发 onTextChanged 事件。

您是否考虑过在以编程方式设置标志之前设置一个标志,以便下次调用它时您可以知道不要添加后缀?

另一种方法是仅在用户提交您的表单后添加后缀。

关于具有固定后缀的 Android EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4053994/

相关文章:

android - 设计器布局在自定义对话框中未正确显示

android - Realm 5.8.0导致Android下dex错误

android - 如何将图像 move 到Android中的原始位置?

Android:EditText 中的多行和无自动建议

android - 在 Android 中倾斜 TextView

android - Kotlin 中的NotificationCompat 困难

android - EditText 只允许所有语言的字母、数字

android - recyclerview 内的多行编辑文本未正确滚动

java - EditText 在 NestedScrollView 内不可滚动

android - 如何使用 xml 设置 EditText 的边距?