Button showHideButton = findViewById(R.id.show_hide_button); ViewGroup viewGroup = findViewById(R.id.view_group); showHideButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (viewGroup.getVisibility() == View.VISIBLE) { viewGroup.setVisibility(View.GONE); } else { viewGroup.setVisibility(View.VISIBLE); } } });
ViewGroup viewGroup = findViewById(R.id.view_group); if (conditionIsMet()) { viewGroup.setVisibility(View.GONE); } else { viewGroup.setVisibility(View.VISIBLE); }This code gets a reference to a view group and checks if a certain condition is met. If it is, it sets the visibility of the view group to `GONE`, otherwise it sets it to `VISIBLE`. `android.view` is the package containing the `View` and `ViewGroup` classes, among others.