textinputlayout errorenabled and showing errors

試著忘記壹切 提交于 2019-12-12 03:34:08

问题


So I have login form, when user click login I will check the inputs.

First what I do, onlick of login button i call textinputlayout.seterrorenabled(false), then when API call is over and I have an error on my editttext i call textinputlayout.seterrorenabled(true), textinputlayout.seterror(message). Everything is all good, now I click on login again and repeat same process textinputlayout.seterrorenabled(false) and then after API call is over textinputlayout.seterrorenabled(true), textinputlayout.seterror(message). However this time the message doesn't show up. What's the problem?

          <android.support.design.widget.TextInputLayout
                android:id="@+id/usernameField1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <EditText
                    android:id="@+id/usernameField"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/user_name"
                    android:textColorHint="#808080"
                    android:paddingBottom="@dimen/tendp"
                    android:paddingLeft="@dimen/tendp"
                    android:paddingRight="@dimen/tendp"
                    android:paddingTop="@dimen/tendp"
                    android:textSize="@dimen/textSize" />
            </android.support.design.widget.TextInputLayout>
            <android.support.design.widget.TextInputLayout
                android:id="@+id/passwordField1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <EditText
                    android:id="@+id/passwordField"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/password"
                    android:textColorHint="#808080"
                    android:paddingBottom="@dimen/tendp"
                    android:inputType="textPassword"
                    android:paddingLeft="@dimen/tendp"
                    android:paddingRight="@dimen/tendp"
                    android:paddingTop="@dimen/tendp"
                    android:textSize="@dimen/textSize" />
            </android.support.design.widget.TextInputLayout>
                <Button
                    android:id="@+id/login"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:background="?attr/selectableItemBackground"
                    android:text="@string/login"
                    android:visibility="gone"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/textSize" >
                </Button>



  final Button login =  (Button) findViewById(R.id.login);
    //  login.setOnClickListener(new OnClickListener() {

        login.setOnClickListener(here i set my textinputlayout to errorenabled false or seterror null // start an asynctask 



  here in asynctask onpostexecute i set the errorenabled(true) and set error( the message)

回答1:


Do not use textinputlayout.seterrorenabled(true) or textinputlayout.seterrorenabled(true) just textinputlayout.seterror(message) if you want to display message or textinputlayout.seterror(null) if you dont



来源:https://stackoverflow.com/questions/36233947/textinputlayout-errorenabled-and-showing-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!