In Java, I have an object that creates a button. Inside that button’s onclicklistener I want to reference the object that created the button.
Is there some easy way I can do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends how you structured it. In general, instances don’t have a reference to the instance that created them unless you pass it in and store it somewhere. However, if you’re doing:
then you can refer to the outer
YourClass, usingYourClass.this