gpt4 book ai didi

android - 如何关闭 TextInputLayout 中的错误?

转载 作者:行者123 更新时间:2023-12-03 23:45:52 25 4
gpt4 key购买 nike

我将 TextInputLayout 用于 EditText,如果我调用 TextInputLayout.setError() 方法,我会看到错误 View - 没关系。

<android.support.design.widget.TextInputLayout
android:id="@+id/text_i_l"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="text"
android:singleLine="true" />

</android.support.design.widget.TextInputLayout>

但是当我开始向 EditText 输入数据时,这个错误并没有隐藏。如何关闭此错误?

最佳答案

很简单,要检测 TextInputLayout 的变化,添加一个 TextWatcher:

TextInputLayout.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

TextInputLayout.setErrorEnabled(false) // disable error
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void afterTextChanged(Editable s) {
}
});

关于android - 如何关闭 TextInputLayout 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36741894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com