Question

i really need help.

This is how my application looks like. I got two(2) fragments where the left side is for the buttons and for the right side is for my details.

The bigger fragment has a default display which i called splash. An image is viewed here, a bigger image that would take the height of the device.

So my case is when i click/press button 1, it would display the fragment for that but the image is still present.
My question now is, how to i get rid of the 'splash display'?

Here is my code

/**
 * on main listener
 */
@Override
public void onMainListener(String whatPress){
    Fragment fr = null;

     if(whatPress.equals("button1"))
         fr = new FragmentOne();
     if(whatPress.equals("button2"))
         fr = new FragmentTwo();
     if(whatPress.equals("button3"))
         fr = new FragmentThree();

     FragmentManager fm = getFragmentManager();
     FragmentTransaction fragmentTransaction = fm.beginTransaction();
     fragmentTransaction.replace(R.id.detailFragment, fr, whatPress);
     fragmentTransaction.commit();
}

The code above is the one handles which button is pressed.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<fragment
    android:id="@+id/menuFragment"
    android:name="FragmentMenu"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="match_parent"
    class="com.mizsh.Fragment_Menu" />

<fragment
    android:id="@+id/detailFragment"
    android:name="com.mizsh.Fragment_Splash"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="match_parent" />

</LinearLayout>

The code above is my main.xml

Figure 1

Was it helpful?

Solution

You should replace the detailFragment with FrameLayout

<FrameLayout android:id="@+id/detailFragment" android:layout_weight="1"
    android:layout_width="0px" android:layout_height="match_parent" />

and replace it with Fragment_Splash in the onCreate of the activity

FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.detailFragment, fragmentSplash, null);
fragmentTransaction.commit();

then replace with chosen fragment on click

FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(R.id.detailFragment, chosenFragment, null);
fragmentTransaction.commit();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top