In android using getLayoutInflater method in LayoutInflater class we can get current layout object.
Example Code:
UI Layout (mainlayout.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
Here if we want to get current layout object use below code.
LayoutInflater inflater = getLayoutInflater();
RelativeLayout root= (RelativeLayout) inflater.inflate(R.layout.mainlayout,null);
And we can access Button using root object
Button button= (Button) root.findViewById(R.id.record);
Example Code:
UI Layout (mainlayout.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
style="?android:attr/buttonStyleSmall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
Here if we want to get current layout object use below code.
LayoutInflater inflater = getLayoutInflater();
RelativeLayout root= (RelativeLayout) inflater.inflate(R.layout.mainlayout,null);
And we can access Button using root object
Button button= (Button) root.findViewById(R.id.record);
No comments:
Post a Comment