Mohamed Gouda Mohamed Gouda - 1 year ago 95
Android Question

Android - Fragment with two buttons

I am working on building an Android application that has a fragment with two buttons, either "News" or "Social". It gets initialised with news, and then if "Social" button is clicked during runtime, it should refresh the fragment with the social's relevant content. Is there a way to do that?

Print screen showing what i want to achieve

Answer Source

One way to do it is putting two views on the fragment and show/hide properly:

<!-- News -->
<FrameLayout
    android:id="@+id/news_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- News content -->

    </FrameLayout>

<!-- Social -->
<FrameLayout
    android:id="@+id/social_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Social content -->

</FrameLayout>

Then, on Java, you use these containers:

// show news and hide social example
socialContainer.setVisibility(View.GONE)
newsContainer.setVisibility(View.VISIBLE)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download