I have the same View inflated (from XML) multiple times. When I call findViewById(R.id.my_layout).setVisibility(View.GONE) I want to apply it on all such views.
How do I do that?
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.
There isn’t a version of
findViewById()that returns all matches; it just returns the first one. You have a few options:When you inflate them, store the reference in an
ArrayList, like this:Then when you inflate:
Then when you want to hide them:
Depending on what you’re doing with these Views, the parent layout may have a way of accessing them. E.g., if you’re putting them in a
ListViewor some such. If you know the parent element you can iterate through the children:If the above options don’t work for you, please elaborate on why you’re doing this.