title: Android - Fragment is behind Buttons from Activity
body: <p>So I have an activity with 2 empty ListView's and 3 Buttons. The "Hinzufügen" Button (seen in Screenshot) should load a Fragment into a Framelayout (used as Container) to lay over all components (ListView's and Buttons) from the activity. But I don't know why it lays behind all of them (can't click the Button of the Fragment because it's behind an empty ListView).</p>
  
  <p>Screenshot without Fragment started:
  <a href="https://abload.de/img/dqwdwqemuhi.jpeg" rel="nofollow noreferrer">https://abload.de/img/dqwdwqemuhi.jpeg</a></p>
  
  <p>Screenshot with Fragment started:
  <a href="https://abload.de/img/fewqfewp7u0b.jpeg" rel="nofollow noreferrer">https://abload.de/img/fewqfewp7u0b.jpeg</a></p>
  
  <p>If I get the container with</p>
  
  <pre><code>View view = findViewById(R.id.container);
  </code></pre>
  
  <p>and then use</p>
  
  <pre><code>view.bringtToFront();
  </code></pre>
  
  <p>the Buttons from the activity are still shown but the ListView's are in the background (can click the button from the fragment now).</p>
  
  <p>How do I get the buttons from the activity in the background so that the fragment lays over the whole activity and its components?</p>
  
  <p>Activity XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="superhelden.com.superheldenuebersichtsapp.Activities.DeckOverview"&gt;
  
  &lt;FrameLayout
      android:id="@+id/addCardsContainer"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginBottom="20dp"
      android:layout_marginLeft="20dp"
      android:layout_marginRight="20dp"
      android:layout_marginTop="20dp"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"&gt;
  
  &lt;/FrameLayout&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline3"
      android:orientation="horizontal"
      app:layout_constraintGuide_percent="0.65"
      tools:layout_editor_absoluteY="332dp"
      tools:layout_editor_absoluteX="0dp" /&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline4"
      android:orientation="vertical"
      app:layout_constraintGuide_percent="0.4"
      tools:layout_editor_absoluteY="0dp"
      tools:layout_editor_absoluteX="154dp" /&gt;
  
  &lt;Button
      android:id="@+id/addCards"
      android:layout_width="wrap_content"
      android:layout_height="0dp"
      android:layout_marginEnd="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginStart="8dp"
      android:text="@string/addCards"
      app:layout_constraintRight_toLeftOf="@+id/guideline4"
      app:layout_constraintTop_toTopOf="@+id/guideline3"
      android:layout_marginTop="8dp"
      android:layout_marginLeft="8dp"
      app:layout_constraintLeft_toLeftOf="parent" /&gt;
  
  &lt;Button
      android:id="@+id/removeCards"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginTop="8dp"
      android:text="@string/removeCards"
      app:layout_constraintBottom_toTopOf="@+id/guideline5"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toLeftOf="@+id/guideline4"
      app:layout_constraintTop_toBottomOf="@+id/addCards"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp" /&gt;
  
  &lt;Button
      android:id="@+id/endGame"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginTop="8dp"
      android:text="@string/endGame"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toLeftOf="@+id/guideline4"
      app:layout_constraintTop_toTopOf="@+id/guideline5"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp" /&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline5"
      android:orientation="horizontal"
      app:layout_constraintGuide_percent="0.88"
      tools:layout_editor_absoluteY="450dp"
      tools:layout_editor_absoluteX="0dp" /&gt;
  
  &lt;ListView
      android:id="@+id/amountOfTypesList"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginLeft="8dp"
      android:layout_marginTop="8dp"
      app:layout_constraintLeft_toLeftOf="@+id/guideline4"
      app:layout_constraintTop_toTopOf="@+id/guideline3"
      android:layout_marginRight="8dp"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintBottom_toBottomOf="parent"
      android:layout_marginBottom="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp" /&gt;
  
  &lt;ListView
      android:id="@+id/deckList"
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginBottom="8dp"
      android:layout_marginEnd="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginStart="8dp"
      android:layout_marginTop="8dp"
      android:divider="#000"
      android:dividerHeight="0.5dp"
      android:scrollbars="horizontal"
      app:layout_constraintBottom_toTopOf="@+id/guideline3"
      app:layout_constraintHorizontal_bias="0.0"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintVertical_bias="0.0" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Activity Java:</p>
  
  <pre><code>public class DeckOverview extends AppCompatActivity {
  
  FragmentManager fragmentManager;
  FragmentTransaction fragmentTransaction;
  Button addCardsButton;
  Button removeCardsButton;
  Button endGameButton;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_deck_overview);
      addCardsButton = (Button) findViewById(R.id.addCards);
      addCardsButton.setOnClickListener(new View.OnClickListener(){
          @Override
          public void onClick(View v) {
              fragmentManager = getFragmentManager();
              fragmentTransaction = fragmentManager.beginTransaction();
              fragmentTransaction.replace(R.id.addCardsContainer, new addCards());
              fragmentTransaction.addToBackStack("addCards");
              fragmentTransaction.commit();
          }
      });
      removeCardsButton = (Button) findViewById(R.id.removeCards);
      removeCardsButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              //TODO: Karten aus Tabelle in der DB entfernen
          }
      });
      endGameButton = (Button) findViewById(R.id.endGame);
      endGameButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(getApplicationContext(), EndScreen.class);
              startActivity(intent);
              finish();
          }
      });
  }
  
  }
  </code></pre>
  
  <p>Fragment XML:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/colorAccent"
  tools:context="superhelden.com.superheldenuebersichtsapp.Fragments.addCards"&gt;
  
  &lt;ListView
      android:id="@+id/allCardsList"
      android:layout_width="0dp"
      android:layout_height="0dp"
  
      app:layout_constraintBottom_toTopOf="@+id/guideline7"
      app:layout_constraintHorizontal_bias="0.0"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toLeftOf="@+id/guideline6"
      app:layout_constraintTop_toTopOf="@+id/guideline10"
  
      style="@style/Margin_And_Divider_Style"/&gt;
  
  &lt;ListView
      android:id="@+id/selectedCardsList"
      android:layout_width="0dp"
      android:layout_height="0dp"
  
      app:layout_constraintBottom_toTopOf="@+id/guideline7"
      app:layout_constraintLeft_toLeftOf="@+id/guideline6"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="@+id/guideline10"
  
      style="@style/Margin_And_Divider_Style"/&gt;
  
  &lt;Button
      android:id="@+id/doneButtonAddCards"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginTop="8dp"
      android:text="@string/done"
      android:layout_marginStart="8dp"
      android:layout_marginEnd="8dp"
  
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="@+id/guideline7"
      app:layout_constraintVertical_bias="0.571" /&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline6"
      android:orientation="vertical"
      app:layout_constraintGuide_percent="0.5"
      tools:layout_editor_absoluteY="0dp"
      tools:layout_editor_absoluteX="180dp" /&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline7"
      android:orientation="horizontal"
      app:layout_constraintGuide_percent="0.86"
      tools:layout_editor_absoluteY="439dp"
      tools:layout_editor_absoluteX="0dp" /&gt;
  
  &lt;android.support.constraint.Guideline
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/guideline10"
      android:orientation="horizontal"
      app:layout_constraintGuide_percent="0.1"
      tools:layout_editor_absoluteY="51dp"
      tools:layout_editor_absoluteX="0dp" /&gt;
  
  &lt;SearchView
      android:layout_width="0dp"
      android:layout_height="0dp"
      android:layout_marginTop="8dp"
      android:layout_marginBottom="8dp"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:id="@+id/searchView"
  
      app:layout_constraintBottom_toTopOf="@+id/guideline10"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Fragment Java:</p>
  
  <pre><code>List&lt;Card&gt; allCardsList;
  ListView allCardsListView;
  
  View addCards;
  
  public addCards() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      allCardsList = DbClass.getInstance(getActivity()).getAllCards();
      allCardsListView = (ListView) getActivity().findViewById(R.id.allCardsList);
  
      Toast.makeText(getActivity(), allCardsList.get(0).getName(), Toast.LENGTH_SHORT).show();
      addCards = inflater.inflate(R.layout.fragment_add_cards, container, false);
  
      return addCards;
  }
  </code></pre>