• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

KOTLIN : HOW TO MAKE A FRAGMENT VISIBLE PROGRAMATICALLY

MAN, DO I NEED HELP!!

I have a MainActivity.kt along with its related MainActivity.xml.

I also have a Fragment that is a part of the MainActivity and it is consists of a MyFragment.kt and MyFragment.xml.
Within the MyFragment.xml I've specified that the MyFragment is Invisible, which means that wne the app starts and the MainActivity gets laid out, that MyFragment is not visible to the user.

I also have a MakeMyFragmentVisibleButton that's part of the MainActivity which, when clicked, I want to cause the MyFragment to become visible.

I am ASSUMING that while the MyFragment is INvisible no buttons or other controls that might be IN that MyFragmment are effectgivly UN-available to the user. He can't see them, can't interact with them.

BUT when the MakeMyFragmentVisibleButton is clicked by the user I want the MyFragment to become visible and thereby make any controls that might be within the MyFragment become visble and the user can interact with them.

That is how I WANT it to work.

BUT I can't figure out how to cause the MyFragment to become visible. I have succeeded in setting an onClickListener for the Button and it does indeed get called when the user clicks the button. But I haven't figure out WHAT CODE actually must run in order to make the MyFragment VISIBLE.

I looked at dozens of YouTube videos and online documents but they all seem to be written in JAVA. My app is in Kotlin which, unfortunately I have zero experience with (I have 45 years experience as a software engineer but I"m baffled by Kotlin).

So, if someone could PLEASE enlighten me as to what I need to do in Kotlin code to cause a Fragment to become visible (and correspondingly IN-visible) I would really appreciate it.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones