title: Referring include layout in activity code android
body: <p>I just want to know if its possible or not? I am using include tag in a layout xml file of an activity</p>
  
  <p>layout.xml</p>
  
  <pre><code>&lt;LinearLayout 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" 
      android:padding="5dp"&gt;
  
      &lt;include android:id="@+id/error_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          layout="@layout/error_xml"
        android:visibility="gone"/&gt; --- at first keeping it invisible
  
  &lt;EditText 
          android:id="@+id/edit"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp"
          android:paddingLeft="10dp"
         /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>erro_xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/error_linear"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal" 
       android:background="@drawable/error_bg"
       android:weightSum="1"
       android:layout_marginTop="10dp"
       android:visibility="gone" &gt;
  
     &lt;TextView android:id="@+id/error_txt"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:textColor="@color/white"
      android:textSize="16sp"
  
       android:layout_weight="0.9"
       android:padding="10dp"/&gt; 
  
     &lt;ImageView android:id="@+id/error_cross"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
  
      android:src="@drawable/squarecross"
       android:layout_weight="0.1"
     android:layout_marginTop="6dp"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>For some reasons I wish to display the included layout on some conditions that are processed dynamically in activity code</p>
  
  <p>I know we can refer EditText and etc views by writing the below code:</p>
  
  <pre><code>EditText edit = (EditText)findViewById(R.id.edit);
  </code></pre>
  
  <p>Can I also refer the include tag layout like the above code? Is it possible? or do I have to inflate it? But how? I am too confused.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>As Answered BY MathanG -- when I used reference of linearlayout in fragment i.e.</p>
  
  <pre><code>LinearLayout error_layout = (LinearLayout)rootView.findViewById(R.id.error_layout);
  </code></pre>
  
  <p>the above statement worked when used  in fragment.. But when I am trying to refer the same through activity it is giving me null pointer exception</p>