I am facing this problem and i want to find the reason that what is the need of passing this , to button & setOnClickListener .
Asked
Active
Viewed 206 times
-3
-
Because its syntax is like that – user2060383 Mar 01 '13 at 08:22
-
Views need a context reference to the activity. – NaviRamyle Mar 01 '13 at 08:23
-
Refer to my answer, This will help you. http://stackoverflow.com/questions/14996466/what-is-the-difference-betweeen-intentgetapplicationcontext-class-and-inten/14996494#14996494 – Manish Dubey Mar 01 '13 at 08:38
-
Am i true i :-- context is same as "this" in java . – Tushar Pandey Mar 01 '13 at 09:20
1 Answers
5
Context is interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
Button is also resource of application so if you want to create button or any widget then you have to pass Context in constructor of widget.
For more details

Rahul
- 44,383
- 11
- 84
- 103