There are times when we do not want the EditText component to gain focus and have the input keyboard show up.
What I wanted was the input keyboard to only show up when I tap on the EditText component.
Well, there is a solution to this without using code. Just add the attribute android:focusableInTouchMode=”true” in your layout where the EditText is part of and it won’t show the keyboard whenever the Activity starts.
There is a big chance that you did this within the onCreate() method of the Activity class and you wondered why if with the click of the button, it works.
I read a post from the Stack Overflow forum that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity because the AnimationDrawable is not yet fully attached to the window.
A good suggestion by user will is to create an inner class where you trigger the start() method of the AnimationDrawable. Try the sample inner class below in your class. It should work.
The method below matches all words that starts with a slash and no other slash should be found within the String. Using regex, I used a positive look behind approach that whenever a slash character is found, it should check if the previous character is a space character while the whole word should also be followed by a space character as well.
This way, the regex pattern ensures that the first chracter should be a slash and any characters following it are accepted such that there should be a space character at the end.
The regex does have a little limitation. What if the very first character of the String is a slash? Then it would not match that word because there is no previous space character before it. The only workaround for this one was to check if the String starts with a slash and if so, manually add a space character at the very first index of the String.