title: enabling or disabling validation for a particular EditTextView dynamically though program
body: <p>MainActivity.XML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"&gt;
  
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          android:layout_marginTop="50dp"&gt;
  
  
      &lt;android.support.v7.widget.CardView
          android:id="@+id/first_name_card"
          android:layout_width="match_parent"
          android:layout_height="@dimen/card_view_height_patient"
          android:layout_marginLeft="10dp"
          android:layout_marginBottom="10dp"
          android:elevation="20dp"
          app:cardCornerRadius="5dp"&gt;
  
  
          &lt;EditText
              android:id="@+id/first_name"
              android:layout_width="match_parent"
              android:layout_height="@dimen/text_input_height"
              android:background="@color/white"
              android:backgroundTint="@color/white"
              android:drawablePadding="@dimen/drawable_padding"
              android:hint="First Name"
              android:imeOptions="actionNext"
              android:maxLength="35"
              android:inputType="textPersonName"
              android:maxLines="1"
              android:textSize="@dimen/edit_text_size"
              android:padding="10dp"
              /&gt;
      &lt;/android.support.v7.widget.CardView&gt;
  
  
  
  
  
  
      &lt;android.support.v7.widget.CardView
          android:id="@+id/last_name_card"
          android:layout_width="match_parent"
          android:layout_height="@dimen/card_view_height_patient"
          android:layout_marginLeft="10dp"
          android:elevation="20dp"
          app:cardCornerRadius="5dp"
          android:layout_marginBottom="10dp"&gt;
  
          &lt;EditText
              android:id="@+id/last_name"
              android:layout_width="match_parent"
              android:layout_height="@dimen/text_input_height"
              android:background="@color/white"
              android:backgroundTint="@color/white"
              android:drawablePadding="@dimen/drawable_padding"
              android:hint="Last Name"
              android:imeOptions="actionNext"
              android:maxLength="35"
              android:inputType="textPersonName"
              android:maxLines="1"
              android:textSize="@dimen/edit_text_size"
              android:padding="10dp"/&gt;
  
      &lt;/android.support.v7.widget.CardView&gt;
  
  
  
  
  
  
      &lt;android.support.v7.widget.CardView
          android:layout_width="match_parent"
          android:layout_height="@dimen/card_view_height_patient"
          android:layout_marginRight="@dimen/margin_low"
          android:layout_marginLeft="10dp"
          android:layout_gravity="bottom"
          app:cardCornerRadius="5dp"
          android:elevation="20dp"
          android:layout_marginBottom="10dp"&gt;
  
          &lt;Spinner
              android:id="@+id/doctors_list"
              android:layout_width="match_parent"
              android:layout_height="@dimen/spinner_height"
              android:gravity="left"&gt;
          &lt;/Spinner&gt;
  
      &lt;/android.support.v7.widget.CardView&gt;
  
  
      &lt;android.support.v7.widget.CardView
          android:id="@+id/ref_name_card"
          android:layout_width="match_parent"
          android:layout_height="@dimen/card_view_height_patient"
          android:layout_marginLeft="10dp"
          android:elevation="20dp"
          android:layout_marginBottom="10dp"
          app:cardCornerRadius="5dp"&gt;
  
          &lt;EditText
              android:id="@+id/reference"
              android:layout_width="match_parent"
              android:layout_height="@dimen/text_input_height"
              android:background="@color/white"
              android:backgroundTint="@color/white"
              android:drawablePadding="@dimen/drawable_padding"
              android:hint="Reference"
              android:imeOptions="actionNext"
              android:inputType="textPersonName"
              android:maxLength="70"
              android:maxLines="1"
              android:textSize="@dimen/edit_text_size"
              android:padding="10dp"/&gt;
  
      &lt;/android.support.v7.widget.CardView&gt;
  
  
  
  
          &lt;Button
              android:id="@+id/submit_button"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="15dp"
              android:layout_marginRight="15dp"
              android:layout_marginTop="10dp"
              android:layout_marginBottom="10dp"
              android:text="Submit"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>MainActivity.Java</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
  
      private EditText firstName;
      private EditText lastName;
      private Spinner selDoc;
      private EditText reference;
      private Button submitBut;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          firstName = findViewById(R.id.first_name);
          lastName = findViewById(R.id.last_name);
          selDoc = findViewById(R.id.doctors_list);
          reference = findViewById(R.id.reference);
          submitBut = findViewById(R.id.submit_button);
  
          String[] dicList = getResources().getStringArray(R.array.doctors_list);
          ArrayAdapter&lt;String&gt; docAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, dicList);
          selDoc.setAdapter(docAdapter);
  
          setOnListnerClickedItems();
          setListeners();
  
      }
  
  
      private void setOnListnerClickedItems() {
  
          submitBut.setOnClickListener(this);
      }
  
      private void setListeners() {
  
          lastName.setVisibility(View.INVISIBLE);
  
      }
  
  
      @Override
      public void onClick(View view) {
          int id = view.getId();
  
          switch (id) {
              case R.id.submit_button:
  
                  String errorMsg = validate();
  
                  if (errorMsg.toString().isEmpty()) {
  
                      Toast.makeText(MainActivity.this, "Data Saved Successfully", Toast.LENGTH_SHORT).show();
  
                  } else {
                      Toast.makeText(MainActivity.this, errorMsg, Toast.LENGTH_SHORT).show();
                  }
                  break;
          }
      }
  
  
  
  
      private String validate() {
          if (ComponentUtils.getInputStringFromView(firstName).toString().isEmpty()) {
              return "Please Enter Your First Name";
          }
          else if (!Validator.isValidName(ComponentUtils.getInputStringFromView(firstName))) {
              return "Please Enter Valid First Name";
          }
          else if (ComponentUtils.getInputStringFromView(lastName).toString().isEmpty()) {
              return "Please Enter Your Last Name";
          }
          else  if (!Validator.isValidName(ComponentUtils.getInputStringFromView(lastName))) {
              return "Please Enter Valid Last Name";
          }
          else if (ComponentUtils.getInputStringFromView(selDoc).toString().isEmpty()) {
              return "Please Select Doctor";
          }
          else if (ComponentUtils.getInputStringFromView(reference).toString().isEmpty()) {
              return "Please Enter Reference Name";
          }
          else if (!Validator.isValidReferenceName(ComponentUtils.getInputStringFromView(reference))) {
              return "Please Enter Valid Reference Name";
          }
  
          else {
              return "";
          }
      }
  }
  </code></pre>
  
  <p>I have 4 fields in the form including <strong>firstName, lastName, doctorList, and referenceName</strong>. I need to validate all the fields excluding INVISIBLE fields. 
  As given in the code 3 fields are visible and 1 field i.e. lastName is invisible. But, when I am entering data and clicking on the submit button it's showing error as Please Enter the Last Name. How to validate only visible fields dynamically? Please help me.</p>