Tuesday 15 April 2014

java - Button to add a custom layout to android application -



java - Button to add a custom layout to android application -

i have little timesheet application of have added screenshot because easier show seek explain all!

hopefully image can see there needs job number different sites worker , can fill out hours relative each job number time spent on job.so here problem dont know how many job numbers have per week here added in 3 may more or less,could have "add job" button add together 1 of job views underneath each time pressed?

below xml code section add together each time button pressed

<linearlayout android:id="@+id/mainlayoutthree" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > //start of 1st job layout <linearlayout android:id="@+id/layouttwoa" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/beige" android:orientation="horizontal" > <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/jobno" > </textview> <edittext android:id="@+id/edittext3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:maxlines="1"> </edittext> <textview android:id="@+id/textview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/ordhours" > </textview> <edittext android:id="@+id/edittext4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:maxlines="1"> </edittext> </linearlayout> <linearlayout android:id="@+id/layoutthree" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/beige" android:orientation="horizontal" > <textview android:id="@+id/textview5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/overtimehours" /> </linearlayout> <linearlayout android:id="@+id/layoutfour" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/beige" android:orientation="horizontal" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="x1.25" /> <edittext android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:maxlines="1"> </edittext> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="x1.50" /> <edittext android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:maxlines="1"> </edittext> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="x2" /> <edittext android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:maxlines="1"> </edittext> </linearlayout>

you can inflate view in button's onclick shown below:

addbutton.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { layoutinflater inflater = layoutinflater .from(getapplicationcontext()); view view = inflater.inflate(r.layout.job_row_layout, null); containerlayout.addview(view); } });

hope helps.

java android android-layout

No comments:

Post a Comment