title: Limit a EditText to exactly certain number of word count
body: <p>How can we limit the <code>EditText</code> length to certain number of word count (100 words).</p>
  
  <p>Even though copy a large text from some where,while pasting it should accept only 100 words.
  I know we can limit it by character count (<code>maxLength</code>)</p>
  
  <p>I tried with below code, but it doesn't limit it by exactly 100 words and it is allowing copy-paste large text.</p>
  
  <pre><code>editText.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
  
                  int wordsLength = countWords(charSequence.toString());// words.length;
                  // count == 0 means a new word is going to start
                  if (count == 0 &amp;&amp; wordsLength &gt;= MAX_WORD_LIMIT) {
                      int charLength = mDescription.getText().length();
                      setCharLimit(mDescription, charLength &gt; 0 ? charLength - 2 : charLength);
                  } else {
                      removeFilter(mDescription);
                  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>private InputFilter filter;
  
      private void setCharLimit(EditText et, int max) {
          filter = new InputFilter.LengthFilter(max);
          et.setFilters(new InputFilter[]{filter});
      }
  
      private void removeFilter(EditText et) {
          if (filter != null) {
              et.setFilters(new InputFilter[0]);
              filter = null;
          }
      }
  </code></pre>