I just want to know if its possible or not? I am using include tag in a layout xml file of an activity
layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<include android:id="@+id/error_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/error_xml"
android:visibility="gone"/> --- at first keeping it invisible
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="10dp"
/>
</LinearLayout>
erro_xml
<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" >
<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"/>
<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"/>
</LinearLayout>
For some reasons I wish to display the included layout on some conditions that are processed dynamically in activity code
I know we can refer EditText and etc views by writing the below code:
EditText edit = (EditText)findViewById(R.id.edit);
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.
EDIT
As Answered BY MathanG -- when I used reference of linearlayout in fragment i.e.
LinearLayout error_layout = (LinearLayout)rootView.findViewById(R.id.error_layout);
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