EditText setError issue - android

I have set error message by txt1.setError() but it's not working all time I mean
some time Error message is not completely showing . See both images.Give me suggestion.
txt1.setError(getString(R.string.error_card));
Not working

Related

how to set error message below the textinputlayout in databinding using MVVM

I want to set error message below the textinput layout in databinding using MVVM in kotlin
will i was doing i encounter an error : it shows null if the email edit text is empty , it should not do that
You can follow this link: Can i bind an error message to a TextInputLayout?
In the second answer, you will see StringRule. By using that hopefully your problem will be fixed.

findViewById on my EditText returns null error

I am currently a new learner to kotlin and android studio in general, and while creating my app, I wanted to make an editable text box in my activity, and so I initialized my text box like so
val testingbox: EditText = findViewById(R.id.editTexttest)
However, when I press my pushbutton that changes the activity to the next one, I crash my app. So when I went to look at my logcat, it gave me this error
Caused by: java.lang.NullPointerException: findViewById(R.id.editTexttest) must not be null
Initialising my buttons like how I did with the text box seemed to have no errors. Are there any differences between the 2? Any help is appreciated. Thanks.

Setting error enabled to false on TextInputlayout not removing extra space in Android 9.0

I am using basic TextInputLayout. I am setting error when EditText is empty. When user enters some text, I am removing error text like this.
tilPassword.isErrorEnabled = false
tilPassword.error = null
This is working fine and good. The reason for calling tilPassword.isErrorEnabled = false is that it is helping me to remove extra space that TextInputLayout adds to the layout when showing error texts. When user enters some text, I am removing error and also the extra space (that is added by TextInputLayout) as well.
Error message is being removed but extra space is not getting removed in Android 9.0. How to solve this issue?
https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout.html#setErrorEnabled(boolean)
The docs explain:
Enabling this functionality before setting an error message via setError(CharSequence), will mean that this layout will not change size when an error is displayed.
So it would work like so.
Show an error:
tilPassword.setErrorEnabled(true)
tilPassword.setError("Wrong password")
Hide an error:
tilPassword.setError("")
tilPassword.setErrorEnabled(false)
Ensure that you are using the AndroidX version of TextInputLayout:
https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout.html
As the platform version below is deprecated:
https://developer.android.com/reference/android/support/design/widget/TextInputLayout
Ref. someone explaining the source:
https://stackoverflow.com/a/35162822/413127

TextInputLayout not showing error message after clearing

I am using TextInputLayout from com.android.support:design:23.3.0
When I first apply an error it is shown correctly.
mInputPassword.setError(getString(R.string.error_invalid_password));
mInputEmail.setError(getString(R.string.error_field_required));
On the next login attempt I clear the error.
mInputEmail.setError(null);
mInputPassword.setError(null);
Then I run the validation and set the error again using the same code as above but this time the red line is applied but the error text is missing.
Anyone have any ideas on why this might be happening or have experienced similar situations?
I saw something similar reported here but it is for an older version of the design library and don't know if it is still a issue in the verison I am using,
You simply has to do these steps:
setErrorEnabled(true);
setError("error");
for clearing:
setError(null);
setErrorEnabled(false);
repeat the first step to set a new error. setError(null) clears the error message and icon, so I think the view to show is simply gone and setErrorEnabled(false) will reset it.
You are clearing the Error Message String:
mInputEmail.setError(null);
mInputPassword.setError(null);
So when you rerun the validation, you will get a blank string.
If you want the error message to go away, clear the erroneous text from the textview:
mInputEmail.setText("");
mInputPassword.setText("");

android program hangs before onCreate is called (beginner)

I needed some sample code to test out the AudioRecord class and I came across this website
LINK TO THE SOURCE CODE
However the program doesn't run, and hangs after a while. When the program starts it gives blank screen and does not do anything, and after a while a message box pops up saying the program is not responding and whether I want to close it.
So I added Toast.makeText(getApplicationContext(), "HERE", Toast.LENGTH_SHORT).show(); as the first line of onCreate() in MainActivity, but even this toast does not show up on the screen. Where are possible locations where a program may hang, before even calling onCreate()? How can I locate that line of code? I tested it on the emulator.
Don't know if its the exact cause but in the XML layout file it makes references to #+id/textView1 but there is no TextView defined in the XML file.
This may refer to the TextView that the SDK creates by default to show the "Hello World" label but has been removed from the example given.
In fact looking at the code in the layout more, the line android:layout_alignLeft="#+id/textView1" is wrong because it has #+id/ which means it is trying to assign a new id/ to android:layout_alignLeft instead of making it match the value "#id/textView1".

Categories

Resources