Welcome to the Treehouse Community
Looking to learn something new?
vicente lee6,271 Points
Is there a reason why the string of facts are declared inside the onClick method? Can't it be declared after the views?
I was wondering if the array of strings could be declared right after the two findViewById statements?
Yes, you are also right. However, during the course, the teacher mention about the "anonymous class". The reason why the teacher used the "anonymous class" is becuase, the app only needs the String variable when you tap on the button. After then, the String variable will be disappeared.
The only case you declare the String after the findViewById statement would be when other methods share the String Variable. However, in this case, you can see that only onClick uses the String variable.
If you have any further question, please leave the comment. :)