For example,
Button b = (Button) findViewById (R.id...)
TextView t = (TextView) findViewById (R.id..)
Why do we do this? When do we have to 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.
We need to do explicit casting whenever we cast object of some class to its subclass.
findViewById returns object of View class, and to get an object of Button, EditText, etc, from this object we need to do explicit cast.
We need to do explicit casting when we need to access methods and fields defined into subclasses, like
setText().We dont need to explicit cast View, when we need to access only View class’s methods, like:
setOnClickListener().