title: fragments not displaying in framelayout
body: <p><strong>Intro:</strong></p>
  
  <p>To put things into perspective, I am attempting to use fragments to create a Sudoku game. </p>
  
  <p>The Sudoku board consists of 9 sub-grids, each containing 9 cells, so 9 cells in one grid, and 9 of these grids form the Sudoku board, arranged in a 3x3 fashion.</p>
  
  <p><a href="https://i.stack.imgur.com/O3bf4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O3bf4.jpg" alt="enter image description here"></a></p>
  
  <hr>
  
  <p><strong>Method:</strong></p>
  
  <p>Home screen containing some information, of which a <code>GridLayout</code> contains 9 <code>Framelayout</code>s where each Sudoku Fragment will be placed into</p>
  
  <p>The 9 Sudoku Fragments will make up the Sudoku board.</p>
  
  <p><code>sudoku_cell</code> extends a <code>LinearLayout</code> with an <code>onClickListener</code>, since extending a TextView, I was unable to inflate the <code>sudoku_cell</code> layout (<em>Is it possible to do so?</em>)</p>
  
  <p>In my main activity, I have a GridLayout containing 9 FrameLayouts. These layouts have column and row locations set to form a 3x3 matrix, this is where each of the fragments will be added into. </p>
  
  <p>These FrameLayouts are named on a 0-based index: <code>frame00</code>, <code>frame01</code>, <code>frame02</code>, <code>frame10</code>, etc</p>
  
  <hr>
  
  <p><strong>Documentation says:</strong></p>
  
  <p>As mentioned here on <a href="https://developer.android.com/guide/components/fragments.html" rel="nofollow noreferrer">developer.android.com</a>, I am required to have an:</p>
  
  <ul>
  <li>Inflator method for the fragment, i.e. <code>onCreateView()</code> which inflates the fragment</li>
  <li>A <code>Layout</code> container of sorts to root/place the fragment in, in the main activity (in my case)</li>
  <li>A <code>FragmentManager</code> and <code>FragmentTransactionManager</code> to handle the fragments, adding and commiting them.</li>
  </ul>
  
  <hr>
  
  <p><strong>Problem:</strong></p>
  
  <p><strong>TL;DR:</strong> Simply, my fragments are not showing.</p>
  
  <p>After calling the <code>commit()</code>, I expect to see a 3x3 board of <code>sudoku_grid</code> fragments, each containing 9 <code>sudoku_cell</code>s. However, this does not get shown</p>
  
  <p>I have searched SO, reread the documentation, and searched more but cannot understand why it is not showing.</p>
  
  <hr>
  
  <p><strong>I have tried:</strong></p>
  
  <p>When inflating my fragment, I inflate a <code>sudoku_cell</code> layout instead, this does infact show a 9 cell grid. </p>
  
  <p>However each cell should be a grid containing 9 cells, this leads me to believe that there may be an issue on the <code>Sudoku_Grid</code> - <code>Sudoku_Cell</code> side, possibly the <code>sudoku_cell</code> layout is not being inflated correctly or being rooted correctly.</p>
  
  <p>Usually an <code>LayoutInflator</code>, and <code>ViewGroup</code> is passed allowing one to inflate a layout, but in the case of the <code>sudoku_cell</code>, I cannot find such a method to <code>override</code>, is this the cause?</p>
  
  <hr>
  
  <p><strong>The code:</strong></p>
  
  <p><strong>sudoku_cell.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;
      &lt;TextView
              android:id="@+id/cellText"
              android:layout_width="35dp"
              android:layout_margin="1px"
              android:textSize="18dp"
              android:layout_height="35dp"
              android:textAlignment="center"
              android:textColor="@color/clBlack"&gt;
      &lt;/TextView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>SudokuCell.java</strong></p>
  
  <pre><code>public class SudokuCell extends LinearLayout{
  
      private LinearLayout layout;
      private TextView textView;
      private Context mContext;
      private Point location;
      private int index;
  
      public SudokuCell(Context context) {
          super(context);
      }
  
      public SudokuCell(Context context, AttributeSet attrs) {
          super(context, attrs);
          mContext = context;
  
          LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          layout = (LinearLayout) inflater.inflate(R.layout.sudoku_cell, this, true);
  
          textView = layout.findViewById(R.id.cellText);
          setText("");
      }
  
      public void setStaticText(String s){
          if (textView != null) {
              textView.setText(s);
              textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
          }
      }
  
      public void setText(String s){
          if (textView != null)
              textView.setText(s);
      }
  
      public Point getLocation() {
          return location;
      }
  
      public void setLocation(Point location) {
          this.location = location;
      }
  
      public int getIndex() {
          return index;
      }
  
      public void setIndex(int index) {
          this.index = index;
      }
  }
  </code></pre>
  
  <p>9 of these <code>sudoku_cell</code>'s get added to a <code>sudoku_grid</code> as shown below in the <code>onCreateView()</code> and <code>populateGrid()</code> methods:</p>
  
  <p><strong>sudoku_grid.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;GridLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="2px"
          android:id="@+id/grid_layout"
          android:columnCount="3"
          android:rowCount="3"&gt;
  
  &lt;/GridLayout&gt;
  </code></pre>
  
  <p><strong>SudokuGrid.java</strong></p>
  
  <pre><code>public class SudokuGrid extends Fragment{
  
      private GridLayout gridLayout;
      private List&lt;GridFragmentListener&gt; listeners = new ArrayList&lt;&gt;();
      private Context mActitityContext;
      private boolean FRAGMENT_LOCATION_CENTRE;
      private float SCREEN_DP;
      private int GRID_MARGINS_DP = 1;
      private int colorOdd, colorEven;
      private List&lt;Integer&gt; presetGrid;
      private View previousView;
      private Drawable previousViewDrawable;
  
      public void addGridListener(GridFragmentListener gridFragmentListener) {
          listeners.add(gridFragmentListener);
      }
  
      public void removeGridListener(GridFragmentListener gridFragmentListener) {
          listeners.remove(gridFragmentListener);
      }
  
      protected void notifyValueChanged(View value) {
          for (GridFragmentListener listener : listeners) listener.onValueChange(value);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          mActitityContext = getActivity();
          View v = inflater.inflate(R.layout.sudoku_grid, container, false);
  
          //set grid view
          gridLayout = v.findViewById(R.id.grid_layout);
  
          populateGrid();
          return v;
      }
  
      private void populateGrid() {
  
          for (int i = 0; i &lt; 9; i++) {
              SudokuCell sudokuCell = new SudokuCell(mActitityContext);
              sudokuCell.setBackgroundColor(((i % 2) == 0) ? R.color.clOdd : R.color.clEven);
              System.out.printf("Sudoku Cell ID [ index = " + String.valueOf(i) + " ] - getId() = " + sudokuCell.getId());
              sudokuCell.setLocation(getPoint(i));
              sudokuCell.setIndex(i);
              sudokuCell.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      notifyValueChanged(view);
                  }
              });
              sudokuCell.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                  @Override
                  public void onFocusChange(View view, boolean b) {
                      SudokuCell cell = (SudokuCell) view;
                      if (b)
                          view.setBackgroundColor(ContextCompat.getColor(mActitityContext, R.color.clSelected));
                      else
                      view.setBackgroundColor(ContextCompat.getColor(mActitityContext, (cell.getIndex() % 2 == 0) ? R.color.clOdd : R.color.clEven));
                  }
              });
              sudokuCell.setStaticText(String.valueOf(i));
              gridLayout.addView(sudokuCell, i);
          }
      }
  
      private Point getPoint(int i) {
          int y = 0;
          while (i &gt; 2){
              y++;
              i -= 3;
          }
          return new Point(i, y);
      }
  
      @Override
      public void onStart() {
          super.onStart();
          try {
              addGridListener((GridFragmentListener) getActivity());
          } catch (ClassCastException e) {
              throw new ClassCastException(
                      getActivity().getClass().toString()
                              + " does not implement the DetailsFragment.DetailsFragmentListener interface.");
          }
  
      }
  
      @Override
      public void onStop() {
          super.onStop();
          removeGridListener((GridFragmentListener) getActivity());
      }
  }
  </code></pre>
  
  <p>In my main activity, I handle the creation of 9 <code>sudoku_grid</code> fragments which are placed into each respective <code>FrameLayout</code>, to form a 3x3 matrix of <code>Sudoku_Grid</code>s, which will form the Sudoku board</p>
  
  <p><strong>activity_main_sudoku.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context="wrap302.nmu.task1.MainActivitySudoku"
          android:background="@color/clDarkGrey"&gt;
  
      &lt;LinearLayout
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" android:id="@+id/linearLayout2"&gt;
          &lt;TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/textView"
                  android:text="@string/app_title"
                  android:layout_marginTop="5dp"
                  android:layout_marginBottom="5dp"
                  android:textColor="@color/clWhite"
                  android:textAppearance="@style/TextAppearance.AppCompat.Display1"
                  android:textAlignment="center"
                  android:textStyle="bold"
                  android:fontFamily="sans-serif"/&gt;
          &lt;TextView
                  android:text="@string/lblScore"
                  android:textColor="@color/clWhite"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" android:id="@+id/lblScore"
                  android:textAppearance="@style/TextAppearance.AppCompat.Button" android:textAlignment="center"
                  android:layout_marginBottom="5dp"/&gt;
      &lt;/LinearLayout&gt;
  
      &lt;GridLayout
              android:layout_gravity="center"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:columnCount="3"
              android:rowCount="3"
              android:id="@+id/main_sudokugrid_container"&gt;
          &lt;FrameLayout
                  android:layout_column="0"
                  android:layout_row="0"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame00"/&gt;
          &lt;FrameLayout
                  android:layout_column="1"
                  android:layout_row="0"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame01"/&gt;
          &lt;FrameLayout
                  android:layout_column="2"
                  android:layout_row="0"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame02"/&gt;
          &lt;FrameLayout
                  android:layout_column="0"
                  android:layout_row="1"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame10"/&gt;
          &lt;FrameLayout
                  android:layout_column="1"
                  android:layout_row="1"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame11"/&gt;
          &lt;FrameLayout
                  android:layout_column="2"
                  android:layout_row="1"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame12"/&gt;
          &lt;FrameLayout
                  android:layout_column="0"
                  android:layout_row="2"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame20"/&gt;
          &lt;FrameLayout
                  android:layout_column="1"
                  android:layout_row="2"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame21"/&gt;
          &lt;FrameLayout
                  android:layout_column="2"
                  android:layout_row="2"
                  android:layout_width="wrap_content"
                  android:background="@color/clWhite"
                  android:layout_height="wrap_content" android:id="@+id/frame22"/&gt;
      &lt;/GridLayout&gt;
  
      &lt;LinearLayout
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:gravity="center" android:id="@+id/linearLayout"&gt;
          &lt;GridLayout
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:paddingTop="0dp"&gt;
              &lt;Button
                      android:layout_row="0"
                      android:layout_column="0"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn1"
                      android:text="1"/&gt;
              &lt;Button
                      android:layout_row="0"
                      android:layout_column="1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn2"
                      android:text="2"/&gt;
              &lt;Button
                      android:layout_row="0"
                      android:layout_column="2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn3"
                      android:text="3"/&gt;
              &lt;Button
                      android:layout_row="1"
                      android:layout_column="0"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn4"
                      android:text="4"/&gt;
              &lt;Button
                      android:layout_row="1"
                      android:layout_column="1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn5"
                      android:text="5"/&gt;
              &lt;Button
                      android:layout_row="1"
                      android:layout_column="2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn6"
                      android:text="6"/&gt;
              &lt;Button
                      android:layout_row="2"
                      android:layout_column="0"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn7"
                      android:text="7"/&gt;
              &lt;Button
                      android:layout_row="2"
                      android:layout_column="1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn8"
                      android:text="8"/&gt;
              &lt;Button
                      android:layout_row="2"
                      android:layout_column="2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/btn9"
                      android:text="9"/&gt;
              &lt;Button
                      android:layout_row="0"
                      android:layout_column="3"
                      android:layout_rowSpan="3"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="fill_vertical"
                      android:id="@+id/btnClear"
                      android:text="Clear"/&gt;
          &lt;/GridLayout&gt;
      &lt;/LinearLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>MainActivitySudoku.java</strong></p>
  
  <pre><code>public class MainActivitySudoku extends AppCompatActivity implements GridFragmentListener {
  
      private FragmentManager fragmentManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main_sudoku);
          createSudokuGrid();
      }
  
      private void createSudokuGrid() {
          fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransactionManager = fragmentManager.beginTransaction();
  
          fragmentTransactionManager.add(R.id.frame00, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame01, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame02, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame10, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame11, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame12, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame20, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame21, new SudokuGrid());
          fragmentTransactionManager.add(R.id.frame22, new SudokuGrid());
  
          fragmentTransactionManager.commit();
  
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          Toast.makeText(this, "Activity Started &amp; Viewable", Toast.LENGTH_SHORT).show();
      }
  
      // GridFragmentListener
      @Override
      public void onValueChange(View view) {
          //todo something here with received view
      }
  }
  </code></pre>