testingsah
testingsah

Reputation: 81

Visibility on include tag?

I have an XML like:

<FrameLayout>
   ...
   <include layout="..." id="@+id/myId">
   ...
</FrameLayout>

in my code however, it seems I cannot do something like

myId.setVisible(Visiblity.GONE)

This does not work for the <include> but it works for regular TextView for example. How can I approach this?

Upvotes: 0

Views: 200

Answers (1)

SalicBlu3
SalicBlu3

Reputation: 1914

You should be able to toggle the visibility of the included layout.

Java

View myId = findViewById<View>(R.id.myId);
myId.setVisibility(View.GONE);

Kotlin

findViewById<View>(R.id.myId).visibility = View.GONE

The key differences in the my answer and OP are:

  • The GONE flag should come from the View class instead of the Visiblity.
  • The setVisible() function should be setVisibility()

Upvotes: 1

Related Questions