Android : Generating View Dynamically

on Monday, November 3, 2014


I got this screen that have some static and some dynamic views to be created. I want infinity number of views to be created and i think dynamic is the way forward enter image description here


Now all i need is to create the top column with image buttons , the edittext with clientname and the spinner with cash in the xml (this is the layout i have currently) now i want if a user clicks the cart icon the views with product name, quantity and price to be generated dynamically and then the bottom views are also generated via xml


like this


enter image description here


As you can see there're two row of product,quantity and price. Currently this is done via xml can someboy help out how can i generate and arrange the row with quantity and price and product name in between an existing xml layout like this?


NB: the main layout is relative layout and the layout that contains the row to be generated dynamically is this



<LinearLayout
android:id="@+id/laygroup0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lvpaymode"
android:gravity="center"
android:orientation="vertical" >

<AutoCompleteTextView
android:id="@+id/autoproduct0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:drawableLeft="@drawable/ic_shopping_cart_black_24dp"
android:ems="10"
android:hint="@string/strproductname"
android:padding="10dp"
android:singleLine="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >

<EditText
android:id="@+id/autoquantity0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_local_mall_black_24dp"
android:ems="10"
android:hint="@string/strquantity"
android:inputType="numberDecimal"
android:padding="10dp"
android:singleLine="true" >
</EditText>

<EditText
android:id="@+id/autoprice0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_attach_money_black_24dp"
android:ems="10"
android:hint="@string/strprice"
android:inputType="numberDecimal"
android:padding="10dp"
android:singleLine="true" >
</EditText>
</LinearLayout>
</LinearLayout>

0 comments:

Post a Comment