I have a simple activity consisting in 4 views defined in an xml file. For the sake of performance, is it better to access my views by their id or to have member referencing them in my activity ? Is it notably different ?
Thanks
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.
You should call
findViewById()just once for each view that you need to reference in your app. Make this call inonCreate()and save the returned view instances in private member variables. Then you can reference them directly later.findViewById() is expensive, especially if you have a lot of views.
This is pretty much standard Android practice.