0

I Wonder what is and does (this) in this code:

Button btn = new Button(this); 

2 Answers 2

5

this refers to the current object, which is probably the Activity. Activity extends Context, and it is passed as Context to the Button constructor.

Sign up to request clarification or add additional context in comments.

6 Comments

I see. Would it be fine if I omit (this)?
No! you need to pass the context to the Button constructor
Ok. May I write other words in parenthesis? If yes, what would they mean?
I think it is better that you explain the whole problem (in a new question) please add relevant code, and the error that you have. This way is kind of cryptic.
Oh, no, I don't program anything with Java right now. When I read such code, and I don't find explanation on it, I just wonder what it is like and what is its equivalent in Objective-C?
|
4

Its a reference to the Context

1 Comment

I see. Would it be fine if I omit (this)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.