Check before Calling performClick()
In Android, View.performClick is defined as:
Using calling method, view’s OnClickListener can be tested. More commonly, this is used to invoke view click through code. For example, a search button can be clicked when a enter key is entered.
If you use this method, it works mostly well like you expected. However, I’ve noticed that some people often have a problem because they forgot its definition. What do you expect about this example?
searchButton is disabled. Thus, you might think that searchButtonClickListener is not called when performClick method is called. Actually, it is called. How about this example?
This also calls searchButtonClickListener. Let’s see the definition again. It says that this method calls view’s OnClickListener. In short, it doesn’t care the view’s status. However, users will not reach OnClickListener if a view is disabled(or not clickable).
You now understand the difference between performClick and users click. If you call the performClick in order to mimic a user’s click, I suggest to use this helper method.