Skip to main content

Posts

Showing posts with the label inner class

Excellent Example of Inner Class

Many a times, I have asked myself, what is the requirement of Inner Classes, and on top of that Anonymous Inner Classes. Here is one good example. The following is an excerpt from "Android SDK's" documentation: Listeners can be one of the more confusing aspects of UI implementation, but what we are trying to achieve in this case is simple. We simply want an onClick() method to be called when the user presses the confirm button, and we can use that to do some work and return the values of the edited note to the Intent caller. We do this using something called an anonymous inner class. This is a bit confusing to look at unless you have seen them before, but all you really need to take away from this is that you can refer to this code in the future to see how to create a listener and attach it to a button. (Listeners are a common idiom in Java development, particularly for user interfaces.) confirmButton.setOnClickListener(new View.OnClickListener() { public