How can it be:
final Button okButton = (Button)findViewById(R.id.okButton);
This is very clear that it is a variable declaration + assignment, absolutely not an object !
If so, how can I do the following, and actually operate a methods on it ?:
okButton.setOnClickListener(this);
okButton.setOnLongClickListener(this);
??
It makes confusion…
Thanks…
A variable can be an Object
If you look at the documentation for findViewById it takes a parameter of type int and returns a View.
You have prefixed
findViewByIdwith(Button)to tell the system that you are expecting that passing R.id.okButton to findViewById will return a View which is actually an instance of Button (a sub-class of View).That instruction
(Button)casts the View returned byfindViewByIdto the Type Button and assigns it to your variableokButton.So