开发者

Need help to use this

Can any one please make it simple or clear to me how the coder has used (this) here in the last line:

@Override

public void onCreate(Bundle savedInstanceState) 
{ 

开发者_Go百科super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// Set up click listeners for all the buttons

View continueButton = findViewById(R.id.continue_button);

continueButton.setOnClickListener(this);<-----------------------------------

}


this is a reference to an instance of the class that the method belongs too, specifically the current instance. This of this as a variable that always points to the current object.

Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.


They have set the button's on-click listener to be this.

In other words, when the button is clicked, onClick will be invoked on this object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜