java - Android how to add a Linearlayout to another LinearLayout from code -
java - Android how to add a Linearlayout to another LinearLayout from code -
i have linearlayout in main.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/mainlayout" > </linearlayout>
i have made xml file, called item_box.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/item_bg" android:gravity="right" > <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" /> <checkbox android:id="@+id/checkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginright="20dp" android:text="@string/item1" android:textsize="30dp" /> <textview android:id="@+id/textview1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginright="20dp" android:gravity="right" android:text="@string/number1" android:textcolor="@color/number_bg" android:textsize="30dp" /> </linearlayout>
basically, want code (programmatically), add together couple item_box.xml main.xml. how can accomplish this?
linearlayout mainlayout = (linearlayout)findviewbyid(r.id.main); layoutinflater inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service); view itembox = inflater.inflate(r.layout.item_box); mainlayout.addview(itembox);
java android android-linearlayout
Comments
Post a Comment