title: having a condition to fragment adding
body: <p>for the last 4 hours ive been trying to understand how to do it.
  to be clear, i need to add a fragment under a certain condition and for my purpose the condition can be either:
  a. if the parent's id matches to what i seek.
  b. if the fragment's id matches to what i seek.</p>
  
  <p>i tried to put the condition inside the fragment itself:</p>
  
  <pre><code>public class BlockFrag extends Fragment{
  SharedPreferences sp;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  {
      sp =  getActivity().getSharedPreferences("myOptions", Context.MODE_PRIVATE);
      int id = container.getId();//didn't work(i think the container is null for some reason
      switch (id)
      {
          default: return inflater.inflate(R.layout.nothing, container, false);
  
          case (R.id.redFrame): {
              if (sp.getBoolean("redBlock", true)) {
                  return inflater.inflate(R.layout.block_frag, container, false);
              }
          }
          case (R.id.greenFrame): {
              if (sp.getBoolean("greenBlock", true)) {
                  return inflater.inflate(R.layout.block_frag, container, false);
  
          }
  </code></pre>
  
  <p>i also tried to get the condition programatically but i cant understand how to prevent the fragment to automatically generate when i call the layout it's placed.</p>
  
  <p>this is the layout it's placed for example</p>
  
  <pre><code>&lt;FrameLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/redFrame"
          android:layout_weight="0.33333"&gt;
  
  
          &lt;fragment
              android:name="com.example.dor.myapplication.BlockFrag"
              android:id="@+id/blockRed"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              tools:layout="@layout/block_frag"/&gt;
  </code></pre>
  
  <p>this is the fragment's layout if it matters...</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignParentLeft="true"
  android:layout_alignParentStart="true"&gt;
  
  &lt;ImageView
      android:layout_width="118dp"
      android:layout_height="match_parent"
      android:id="@+id/blockFrag"
      android:src="@drawable/block"
      android:layout_weight="0.33333"
      android:layout_above="@+id/linearLayout"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_gravity="left"
      android:scaleType="fitXY"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>thank you for helping, any kind of way to do this will help me.</p>