Form Validation in android TextInputLayout not working correctlyIs there a way to run Python on Android?How to save an Android Activity state using save instance state?Activity restart on rotation AndroidClose/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?Limit text length of EditText in AndroidWhat is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?
Programmatically add log information in all renderings(controller, view) html
Why aren't rainbows blurred-out into nothing after they are produced?
Can sampling rate be a floating point number?
Why command hierarchy, if the chain of command is standing next to each other?
Corroded Metal vs Magical Armor, should it melt it?
Took GRE two times, same scores with minor differences - worth sending both?
Can the IPA represent all languages' tones?
Telephone number in spoken words
Heating Margarine in Pan = loss of calories?
How to display numbers like 10,000.42 using siunitx?
Does Nightpack Ambusher's second ability trigger if I cast spells during the end step?
Iteratively increasing network size during training
Can I enter the USA with an E-2 visa and a one way flight ticket?
How to take the beginning and end parts of a list with simpler syntax?
Why does the standard fingering / strumming for a D maj chord leave out the 5th string?
Loading military units into ships optimally, using backtracking
Are 变 and 変 the same?
How is являться different from есть and быть
In which case does the Security misconfiguration vulnerability apply to?
Submitting a new paper just after another was accepted by the same journal
When does Tiana, Ship's Caretaker check card type?
Are differences between uniformly distributed numbers uniformly distributed?
First amendment and employment: Can a police department terminate an officer for speech?
What is the farthest a camera can see?
Form Validation in android TextInputLayout not working correctly
Is there a way to run Python on Android?How to save an Android Activity state using save instance state?Activity restart on rotation AndroidClose/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?Limit text length of EditText in AndroidWhat is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to validate the form, i am using TextInputLayout error to show the error, when i click submit button in empty form, the error is shown in only Name field, and the error is not hiding when i fill the name text. Also the other fields not showing validation error.
activity_form.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/nameTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_name"
android:inputType="textPersonName"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/EmailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formEmailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_email"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PhoneTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_mobile_number"
android:imeOptions="actionNext"
android:id="@+id/formMobileEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/AlternateTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_alternate_number"
android:imeOptions="actionNext"
android:id="@+id/formAlternateEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/JEETextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:id="@+id/formJeeEdit"
android:hint="@string/form_hint_jee"
android:inputType="number"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PercentageTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_percentage"
android:imeOptions="actionNext"
android:id="@+id/formPerEdit"
android:inputType="numberDecimal"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/CityTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/form_hint_city"
android:id="@+id/formCityEdit"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/deptSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</Spinner>
<Spinner
android:id="@+id/SourceSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
<Button
android:id="@+id/submit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
android:text="@string/form_submit_btn" />
</LinearLayout>
</ScrollView>
FormActivity.java
mSubmitBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Validation();
);
private void Validation()
boolean isValid = true;
String dept = mDepartmentSpinner.getSelectedItem().toString();
String source = mSourceSpinner.getSelectedItem().toString();
String name = NameInputLayout.getEditText().getText().toString();
if(NameInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
Log.d("form error", "Error removed");
String email = EmailInputLayout.getEditText().getText().toString();
if(EmailInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Email");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String phone = PhoneInputLayout.getEditText().getText().toString().trim();
if(phone.isEmpty())
NameInputLayout.setError("Enter Phone Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String alternate_num = AlternateInputLayout.getEditText().getText().toString();
if(alternate_num.isEmpty())
NameInputLayout.setError("Enter Alternate Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String jee_marks = JeeInputLayout.getEditText().getText().toString();
if(jee_marks.isEmpty())
NameInputLayout.setError("Enter Roll Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String percentage = PercentageInputLayout.getEditText().getText().toString();
if(percentage.isEmpty())
NameInputLayout.setError("Enter Percentage");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String city = CityInputLayout.getEditText().getText().toString();
if(city.isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
if(isValid)
Boolean insert = dbHelper.insertForm(name,email,phone,alternate_num,jee_marks,percentage,city,dept,source);
if(insert == true)
Toast.makeText(getApplicationContext(),"Form Submitted",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FormActivity.this, MainActivity.class);
startActivity(intent);
else
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
add a comment |
I am trying to validate the form, i am using TextInputLayout error to show the error, when i click submit button in empty form, the error is shown in only Name field, and the error is not hiding when i fill the name text. Also the other fields not showing validation error.
activity_form.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/nameTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_name"
android:inputType="textPersonName"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/EmailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formEmailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_email"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PhoneTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_mobile_number"
android:imeOptions="actionNext"
android:id="@+id/formMobileEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/AlternateTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_alternate_number"
android:imeOptions="actionNext"
android:id="@+id/formAlternateEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/JEETextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:id="@+id/formJeeEdit"
android:hint="@string/form_hint_jee"
android:inputType="number"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PercentageTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_percentage"
android:imeOptions="actionNext"
android:id="@+id/formPerEdit"
android:inputType="numberDecimal"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/CityTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/form_hint_city"
android:id="@+id/formCityEdit"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/deptSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</Spinner>
<Spinner
android:id="@+id/SourceSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
<Button
android:id="@+id/submit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
android:text="@string/form_submit_btn" />
</LinearLayout>
</ScrollView>
FormActivity.java
mSubmitBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Validation();
);
private void Validation()
boolean isValid = true;
String dept = mDepartmentSpinner.getSelectedItem().toString();
String source = mSourceSpinner.getSelectedItem().toString();
String name = NameInputLayout.getEditText().getText().toString();
if(NameInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
Log.d("form error", "Error removed");
String email = EmailInputLayout.getEditText().getText().toString();
if(EmailInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Email");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String phone = PhoneInputLayout.getEditText().getText().toString().trim();
if(phone.isEmpty())
NameInputLayout.setError("Enter Phone Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String alternate_num = AlternateInputLayout.getEditText().getText().toString();
if(alternate_num.isEmpty())
NameInputLayout.setError("Enter Alternate Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String jee_marks = JeeInputLayout.getEditText().getText().toString();
if(jee_marks.isEmpty())
NameInputLayout.setError("Enter Roll Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String percentage = PercentageInputLayout.getEditText().getText().toString();
if(percentage.isEmpty())
NameInputLayout.setError("Enter Percentage");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String city = CityInputLayout.getEditText().getText().toString();
if(city.isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
if(isValid)
Boolean insert = dbHelper.insertForm(name,email,phone,alternate_num,jee_marks,percentage,city,dept,source);
if(insert == true)
Toast.makeText(getApplicationContext(),"Form Submitted",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FormActivity.this, MainActivity.class);
startActivity(intent);
else
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
add a comment |
I am trying to validate the form, i am using TextInputLayout error to show the error, when i click submit button in empty form, the error is shown in only Name field, and the error is not hiding when i fill the name text. Also the other fields not showing validation error.
activity_form.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/nameTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_name"
android:inputType="textPersonName"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/EmailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formEmailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_email"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PhoneTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_mobile_number"
android:imeOptions="actionNext"
android:id="@+id/formMobileEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/AlternateTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_alternate_number"
android:imeOptions="actionNext"
android:id="@+id/formAlternateEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/JEETextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:id="@+id/formJeeEdit"
android:hint="@string/form_hint_jee"
android:inputType="number"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PercentageTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_percentage"
android:imeOptions="actionNext"
android:id="@+id/formPerEdit"
android:inputType="numberDecimal"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/CityTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/form_hint_city"
android:id="@+id/formCityEdit"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/deptSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</Spinner>
<Spinner
android:id="@+id/SourceSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
<Button
android:id="@+id/submit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
android:text="@string/form_submit_btn" />
</LinearLayout>
</ScrollView>
FormActivity.java
mSubmitBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Validation();
);
private void Validation()
boolean isValid = true;
String dept = mDepartmentSpinner.getSelectedItem().toString();
String source = mSourceSpinner.getSelectedItem().toString();
String name = NameInputLayout.getEditText().getText().toString();
if(NameInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
Log.d("form error", "Error removed");
String email = EmailInputLayout.getEditText().getText().toString();
if(EmailInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Email");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String phone = PhoneInputLayout.getEditText().getText().toString().trim();
if(phone.isEmpty())
NameInputLayout.setError("Enter Phone Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String alternate_num = AlternateInputLayout.getEditText().getText().toString();
if(alternate_num.isEmpty())
NameInputLayout.setError("Enter Alternate Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String jee_marks = JeeInputLayout.getEditText().getText().toString();
if(jee_marks.isEmpty())
NameInputLayout.setError("Enter Roll Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String percentage = PercentageInputLayout.getEditText().getText().toString();
if(percentage.isEmpty())
NameInputLayout.setError("Enter Percentage");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String city = CityInputLayout.getEditText().getText().toString();
if(city.isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
if(isValid)
Boolean insert = dbHelper.insertForm(name,email,phone,alternate_num,jee_marks,percentage,city,dept,source);
if(insert == true)
Toast.makeText(getApplicationContext(),"Form Submitted",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FormActivity.this, MainActivity.class);
startActivity(intent);
else
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
I am trying to validate the form, i am using TextInputLayout error to show the error, when i click submit button in empty form, the error is shown in only Name field, and the error is not hiding when i fill the name text. Also the other fields not showing validation error.
activity_form.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/nameTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_name"
android:inputType="textPersonName"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/EmailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/formEmailEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_email"
android:inputType="textEmailAddress"
android:imeOptions="actionNext"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PhoneTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_mobile_number"
android:imeOptions="actionNext"
android:id="@+id/formMobileEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/AlternateTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_alternate_number"
android:imeOptions="actionNext"
android:id="@+id/formAlternateEdit"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/JEETextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:id="@+id/formJeeEdit"
android:hint="@string/form_hint_jee"
android:inputType="number"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/PercentageTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_hint_percentage"
android:imeOptions="actionNext"
android:id="@+id/formPerEdit"
android:inputType="numberDecimal"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/CityTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="@string/form_hint_city"
android:id="@+id/formCityEdit"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="@+id/deptSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
>
</Spinner>
<Spinner
android:id="@+id/SourceSpinner"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
<Button
android:id="@+id/submit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/roundedbutton"
android:text="@string/form_submit_btn" />
</LinearLayout>
</ScrollView>
FormActivity.java
mSubmitBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Validation();
);
private void Validation()
boolean isValid = true;
String dept = mDepartmentSpinner.getSelectedItem().toString();
String source = mSourceSpinner.getSelectedItem().toString();
String name = NameInputLayout.getEditText().getText().toString();
if(NameInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
Log.d("form error", "Error removed");
String email = EmailInputLayout.getEditText().getText().toString();
if(EmailInputLayout.getEditText().getText().toString().isEmpty())
NameInputLayout.setError("Enter Email");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String phone = PhoneInputLayout.getEditText().getText().toString().trim();
if(phone.isEmpty())
NameInputLayout.setError("Enter Phone Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String alternate_num = AlternateInputLayout.getEditText().getText().toString();
if(alternate_num.isEmpty())
NameInputLayout.setError("Enter Alternate Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String jee_marks = JeeInputLayout.getEditText().getText().toString();
if(jee_marks.isEmpty())
NameInputLayout.setError("Enter Roll Number");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String percentage = PercentageInputLayout.getEditText().getText().toString();
if(percentage.isEmpty())
NameInputLayout.setError("Enter Percentage");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
String city = CityInputLayout.getEditText().getText().toString();
if(city.isEmpty())
NameInputLayout.setError("Enter Name");
isValid = false;
else
NameInputLayout.setErrorEnabled(false);
if(isValid)
Boolean insert = dbHelper.insertForm(name,email,phone,alternate_num,jee_marks,percentage,city,dept,source);
if(insert == true)
Toast.makeText(getApplicationContext(),"Form Submitted",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(FormActivity.this, MainActivity.class);
startActivity(intent);
else
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show();
asked Mar 27 at 10:15
ShubhamShubham
258 bronze badges
258 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
here is code snippet to remove error(user text change listener in edittext) you need to call for every edit text and textinput layout.
public static void addTextChangedListener(EditText e, final TextInputLayout t)
e.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
if (s.length() > 0)
if (!TextUtils.isEmpty(t.getError()))
t.setError(null);
t.setErrorEnabled(false);
@Override
public void afterTextChanged(Editable s)
);
and second thing you are validation EmailInputLayout and setting erroer to NameInputLayout in each input field.
-do copy paste but smartly.
add a comment |
It seems you are using the same textInputlayout (NameInputLayout) with all your fields.
Hence after entering the name , when the else block is executed the errorEnabled is set to false , causing other error to not set.
And for removing error in your else case do the following:-
NameInputLayout.setError(null)
instead of :-
NameInputLayout.setErrorEnabled(false);
Otherwise you will have to set setErrorEnabled to true, again to use it.
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374729%2fform-validation-in-android-textinputlayout-not-working-correctly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
here is code snippet to remove error(user text change listener in edittext) you need to call for every edit text and textinput layout.
public static void addTextChangedListener(EditText e, final TextInputLayout t)
e.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
if (s.length() > 0)
if (!TextUtils.isEmpty(t.getError()))
t.setError(null);
t.setErrorEnabled(false);
@Override
public void afterTextChanged(Editable s)
);
and second thing you are validation EmailInputLayout and setting erroer to NameInputLayout in each input field.
-do copy paste but smartly.
add a comment |
here is code snippet to remove error(user text change listener in edittext) you need to call for every edit text and textinput layout.
public static void addTextChangedListener(EditText e, final TextInputLayout t)
e.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
if (s.length() > 0)
if (!TextUtils.isEmpty(t.getError()))
t.setError(null);
t.setErrorEnabled(false);
@Override
public void afterTextChanged(Editable s)
);
and second thing you are validation EmailInputLayout and setting erroer to NameInputLayout in each input field.
-do copy paste but smartly.
add a comment |
here is code snippet to remove error(user text change listener in edittext) you need to call for every edit text and textinput layout.
public static void addTextChangedListener(EditText e, final TextInputLayout t)
e.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
if (s.length() > 0)
if (!TextUtils.isEmpty(t.getError()))
t.setError(null);
t.setErrorEnabled(false);
@Override
public void afterTextChanged(Editable s)
);
and second thing you are validation EmailInputLayout and setting erroer to NameInputLayout in each input field.
-do copy paste but smartly.
here is code snippet to remove error(user text change listener in edittext) you need to call for every edit text and textinput layout.
public static void addTextChangedListener(EditText e, final TextInputLayout t)
e.addTextChangedListener(new TextWatcher()
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
if (s.length() > 0)
if (!TextUtils.isEmpty(t.getError()))
t.setError(null);
t.setErrorEnabled(false);
@Override
public void afterTextChanged(Editable s)
);
and second thing you are validation EmailInputLayout and setting erroer to NameInputLayout in each input field.
-do copy paste but smartly.
answered Mar 27 at 10:26
Amit GoswamiAmit Goswami
946 bronze badges
946 bronze badges
add a comment |
add a comment |
It seems you are using the same textInputlayout (NameInputLayout) with all your fields.
Hence after entering the name , when the else block is executed the errorEnabled is set to false , causing other error to not set.
And for removing error in your else case do the following:-
NameInputLayout.setError(null)
instead of :-
NameInputLayout.setErrorEnabled(false);
Otherwise you will have to set setErrorEnabled to true, again to use it.
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
add a comment |
It seems you are using the same textInputlayout (NameInputLayout) with all your fields.
Hence after entering the name , when the else block is executed the errorEnabled is set to false , causing other error to not set.
And for removing error in your else case do the following:-
NameInputLayout.setError(null)
instead of :-
NameInputLayout.setErrorEnabled(false);
Otherwise you will have to set setErrorEnabled to true, again to use it.
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
add a comment |
It seems you are using the same textInputlayout (NameInputLayout) with all your fields.
Hence after entering the name , when the else block is executed the errorEnabled is set to false , causing other error to not set.
And for removing error in your else case do the following:-
NameInputLayout.setError(null)
instead of :-
NameInputLayout.setErrorEnabled(false);
Otherwise you will have to set setErrorEnabled to true, again to use it.
It seems you are using the same textInputlayout (NameInputLayout) with all your fields.
Hence after entering the name , when the else block is executed the errorEnabled is set to false , causing other error to not set.
And for removing error in your else case do the following:-
NameInputLayout.setError(null)
instead of :-
NameInputLayout.setErrorEnabled(false);
Otherwise you will have to set setErrorEnabled to true, again to use it.
answered Mar 27 at 10:26
KaveriKaveri
5426 silver badges14 bronze badges
5426 silver badges14 bronze badges
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
add a comment |
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
Hey thanks for the answer, now the error is showing to every fields when the empty fields are submitted,but when i fill the fields the error is still there.., setError(null) not executing
– Shubham
Mar 27 at 17:50
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
there must be a problem in your condition , try it with a TextUtils.isEmpty(strVar)
– Kaveri
Mar 28 at 3:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55374729%2fform-validation-in-android-textinputlayout-not-working-correctly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown