We can set error in Edittext successfully but failed to set in textview. is there any problem?? i tried
((TextView) findViewById(R.id.df)).requestFocus(); ((TextView) findViewById(R.id.df)).setSelected(true); ((TextView) findViewById(R.id.df)).setError("akjshbd");
but i am not getting popup for error.
Default TextView is NOT focusable. So, you need to set android:focusable="true" and android:focusableInTouchMode="true". And no need to set setSelected(true). I prefer this solution.
You can use the TextInputLayout to display error messages according to the material design guidelines using the setError and setErrorEnabled methods. In order to show the error below the EditText use: TextInputLayout til = (TextInputLayout) findViewById(R. id.
Solution: We can display error message in EditText by using setError() method. <?
Default TextView is NOT focusable. So, you need to set android:focusable="true" and android:focusableInTouchMode="true".
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="true" android:focusableInTouchMode="true" android:text="@string/hello_world" />
And no need to set setSelected(true).
((TextView) findViewById(R.id.df)).requestFocus(); ((TextView) findViewById(R.id.df)).setError("akjshbd");
Actually , you can use the setError for the textView and show its popup .
You just need to use the same style as of the EditText .
Simply add the next attribute for the textView in the xml :
style="@android:style/Widget.EditText"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With