Posts

Showing posts from November, 2014

Java reflection by some Android examples (part 1)

This Thursday, I met an issue while I was fixing bugs for my company project. It was about listening the event occurred when a Spinner drop down list dismissed. I took me 1 working day investigating the Spinner and related classes's source code. The conclusion was that a drop-down styled Spinner contained an object having an onDismissListener, we could set a listener for this object. The only problem is the object was PRIVATE declared inside Spinner, so was its class declaration. Another day for looking for solutions. I then extended the Spinner class for setting a listener and applied reflection technique for accessing something "private". I think this experiences will be helpful for some of you. I will write down what I researched with real-code demo. First of all, here is a little about reflection from  https://docs.oracle.com/javase/tutorial/reflect/ Uses of Reflection  Reflection is commonly used by programs which require the ability to examine or modify th