Question: I created an application in which i had **1 ACTIVITY** and **8 Fragment** in which i am inflating every fragment into the activity. but my problem is that every **fragment is overlapping each other**. I change the background color of every fragment but when i am clicking the vacant spaces button of my previous fragment get clicked.

please suggest me some thing to get out of this situation.

Main\_Activity.class

```
public class ActRegistration extends AppCompatActivity {
    FragmentManager fm;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_registration);
        fm = getSupportFragmentManager();
        loadFragment(new FragmentRegLogSkip(), FragmentRegLogSkip.FRAGMENT_KEY);
    }

    public void loadFragment(Fragment fragmentName, String fragmentKey) {
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.add(R.id.id_registration_layout_frame, fragmentName);
        fragmentTransaction.addToBackStack(fragmentKey);
        fragmentTransaction.commit();
    }
}   

```

Frag\_1.class

```
public class FragmentRegLogSkip extends Fragment implements View.OnClickListener {
    private Activity activity;
    private Context context;
    public static final String FRAGMENT_KEY = "fragment_reg_log_skip";

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getContext();
        LanguageChanger.changeLanguage(context);
        View view = inflater.inflate(R.layout.act_registration_screen_login, container, false);
return view;
}
}

```

Answer: 
Don't forget to add `android:clickable="true"` and `android:focusable="true"` to the parent view of your second fragment so it catches the clicks and they don't get propagated to the fragment below. Something like this:

```
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">   

```
You're using `fragmentTransaction.add()`, which won't remove the previous Fragment - use `fragmentTransaction.replace()` if you want the other Fragment's view to be removed.

Note `FragmentManager` automatically restores any previously added Fragments when your Activity is recreated (i.e., when `savedInstanceState != null`). Therefore you'll want to ensure that you only add your initial Fragment once - when the `savedInstanceState` is null.

```
if (savedInstanceState == null) {
    loadFragment(new FragmentRegLogSkip(), FragmentRegLogSkip.FRAGMENT_KEY);
}

```