AbAppletic AbAppletic - 5 months ago 8
Android Question

Group multiple views into one view in Android

For example, if I have:

EditText A;
TextView B;
ImageView C;


And I want to set all their visibilities to
View.GONE
, how can I do it in a way that instead of this:

A.setVisibility(View.GONE);
B.setVisibility(View.GONE);
C.setVisibility(View.GONE);


I do this:

groupD.setVisibility(View.GONE);


without having to put all of them in one
RelativeLayout
and then setting the
RL
to
View.GONE
? Is there a java class for this? Or do I have to get a Library for it? If not, can I do it manually so I can organize my project which has 30 views? I don't want to set each group to be in its own
RelativeLayout
because all views are dependant on each other.

Answer

The best way will be passing the views to a single method. All of them are Views So you can do something like this.

public void setViews(View view){
 view.setVisibility(View.GONE);
}

And call the method like this

setViews(editText);