I am working on android studio. I have created a linear layout inside a fragment like below :
<LinearLayout
android:id="@+id/ll_out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_round"
android:orientation="vertical"
android:padding="5sp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10sp"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="@+id/tv_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:gravity="left"
android:inputType="text"
android:hint = "Enter Product"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<EditText
android:id="@+id/prod_qty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Enter Quantity"
android:gravity="left"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<EditText
android:id="@+id/prod_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="Prod Price"
android:gravity="left"
android:inputType="none" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<EditText
android:id="@+id/prod_specs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="Prod Specs"
android:gravity="left"
android:inputType="none" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:padding="0dp">
<Button
android:id="@+id/btn_prd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New Product"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
GUI
What do I want to do?
On clicking of Add New Product button, I want to recreate the same Linear Layout along with the textviews.
In the above image, the product names, price, and specs are taken out from the JSON file which is stored in the user mobile.
What I have Tried
Below is the code that I have tried to do
addProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Add product button click " , Toast.LENGTH_SHORT).show();
LinearLayout linearLayoutProduct = new LinearLayout(getActivity());
linearLayoutProduct.findViewById(R.id.ll_out);//Stuck here
}
});
Update 1
I want to make the app like following
In the above picture when I click the plus sign then a new row is created with the cross button and so on. I want exactly the same
How can I do this?
Any help would be highly appreciated.

