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:
1 2 3 |
dependencies { compile 'org.apache.commons:commons-lang3:3.0.+' } |
1 2 3 4 5 |
String keywordsForTextView = searchHistoryItem.getKeywords(); if ( StringUtils.isBlank(keywordsForTextView) ) { Resources res = context.getResources(); keywordsForTextView = res.getString(R.string.no_keywords); } |
And another example with AutoCompleteTextView:
1 2 3 4 5 6 7 |
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