On TextView Hints and StringUtils.isBlank

No comments on On TextView Hints and StringUtils.isBlank

Written by

in

I had a problem caused by setting empty or blank strings to the TextView and AutoCompleteTextView – hints were invisible after that. So I decided to check strings, that are set, if they were not only empty, but also not blank. I used StringUtils.isBlank instead of StringUtils.isEmpty: it works much better now, and hints are always visible. If you don’t still use StringUtils, I highly recommend you to do. This is a Gradle import for a library that contains them:

dependencies {
    compile 'org.apache.commons:commons-lang3:3.0.+'
}
String keywordsForTextView = searchHistoryItem.getKeywords();
if ( StringUtils.isBlank(keywordsForTextView) ) {
      Resources res = context.getResources();
      keywordsForTextView = res.getString(R.string.no_keywords);
}

And another example with AutoCompleteTextView:

public void setKeywords(String keywords) {
   this.keywords = keywords;
   if (StringUtils.isNotBlank(keywords)) {
      Log.v(Helper.TAG, "Setting keywords to the keywordAutoCompleteTextView: " + keywords);
      keywordAutoCompleteTextView.setText(keywords);
   }
}

Here is some information on how isNotEmpty and isNotBlank are working.

Title of this article: On Android TextView and AutoCompleteTextView Hint and StringUtils.isBlank and .isEmpty

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *