whenever the button is clicked, it adds a new row to the TableLayout and notice the Scrollbar from the ScrollView.
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click To Add New row"></Button>
<ScrollView android:id="@+id/ScrollView01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent" android:text="textfield 1-1" android:layout_height="wrap_content" android:id="@+id/TextView01"></TextView>
<ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>
<DigitalClock android:text="DigitalClock" android:layout_width="wrap_content" android:id="@+id/digitalClock1" android:layout_height="wrap_content"></DigitalClock>
<CheckBox android:id="@+id/CheckBox01" android:text="" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click To Add New row"></Button>
<ScrollView android:id="@+id/ScrollView01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent" android:text="textfield 1-1" android:layout_height="wrap_content" android:id="@+id/TextView01"></TextView>
<ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>
<DigitalClock android:text="DigitalClock" android:layout_width="wrap_content" android:id="@+id/digitalClock1" android:layout_height="wrap_content"></DigitalClock>
<CheckBox android:id="@+id/CheckBox01" android:text="" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
public class tablelayout extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button btn;
int counter=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.Button01);
btn.setOnClickListener( this);
}
public void onClick(View view){
TableLayout tl=(TableLayout)findViewById(R.id.TableLayout01);
TableRow tr=new TableRow(this);
counter++;
TextView tv= new TextView(this);
tv.setText("text"+counter);
CheckBox cb=new CheckBox(this);
DigitalClock dc= new DigitalClock(this);
ImageView ib=new ImageView(this);
ib.setImageResource(R.drawable.icon);
tr.addView(tv);
tr.addView(ib);
tr.addView(dc);
tr.addView(cb);
tl.addView(tr,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
}
}
[/source code]
Output Like This.
Output Like This.
NOTE:TableLayout is built using the TableLayout and the TableRow commands. There is no TableCols like the<td> tag in HTML. To align your view in columns you have to set the width of the elements and manually control the layout.So
I really wana thank you for providing such informative and qualitative material so often.
ReplyDeletegoogle android news
can you tell me how to remove row dinamically? thank you
ReplyDeleteAdd one more Button and name as "Click to Remove".
ReplyDeleteremove_btn=(Button)findViewById(R.id.Button02);
Set remove_btn.setOnClickListener( this);
//*** Place this code***//
TableLayout tl=(TableLayout)findViewById(R.id.TableLayout01);
TableRow tr=new TableRow(this);
counter--;
TextView tv= new TextView(this);
tv.setText("text"+counter);
CheckBox cb=new CheckBox(this);
DigitalClock dc= new DigitalClock(this);
ImageView ib=new ImageView(this);
ib.setImageResource(R.drawable.icon);
tr.removeView(tv);
tr.removeView(ib);
tr.removeView(dc);
tr.removeView(cb);
tl.removeView(tr,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
how is it scrolled?
ReplyDeleteIt is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteData Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data science training in kalyan nagar
selenium training in chennai
Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
ReplyDeletepython training in pune
python online training
python training in OMR
Impressive. Your story always bring hope and new energy. Keep up the good work.
ReplyDeleteBlueprism training institute in Chennai
Blueprism online training
Learned a lot from your blog, share more like this.
ReplyDeleteAWS Training in Chennai
DevOps Training in Chennai
Data Science Course in Chennai
ccna course in Chennai
Python Training in Chennai
R Programming Training in Chennai
Angularjs Training in Chennai
RPA Training in Chennai
Blue Prism Training in Chennai
This blog is really helpful for me and got a basic knowledge in this topic. Waiting for more updates, kindly keep continuing.
ReplyDeleteIELTS Classes in Mumbai
IELTS Coaching in Mumbai
Best IELTS Coaching in Mumbai
IELTS Center in Mumbai
IELTS Training in Mumbai
Spoken English in Chennai
Very interesting post! Thanks for sharing your experience suggestions.
ReplyDeleteAviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
Aviation Courses in Chennai
air hostess course in Chennai
Airport Management Training in Chennai
airport ground staff training courses in Chennai
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeleteData science Course Training in Chennai | Data Science Training in Chennai
RPA Course Training in Chennai | RPA Training in Chennai
AWS Course Training in Chennai | AWS Training in Chennai
Can you please let me know how to assign ids to all these elements dynamically ? so that i can save the information .
ReplyDeleteHi, Thanks for sharing nice articles...
ReplyDeleteAWS Training In Hyderabad
Great! Information you have been shared, it’s really very impressive and easy to understand please share more useful information like this. Thank you
ReplyDeleteData Science Training in Hyderabad
ReplyDeleteNice article and thanks for sharing with us. Its very informative
Plots in CHITUKULA
Grab the Digital Marketing Training in Chennai from Infycle Technologies, the best software training institute, and Placement center in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Cyber Security, Big Data, Java, Hadoop, Selenium, Android, and iOS Development, DevOps, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.
ReplyDeleteSome may stag in Interviews!!! OOPS!! More than 50% of students do this in their career. Instead, do Hadoop Training in Chennai at Infycle. Those students can easily clear this Interview session because more than 5 times at INFYCLE practicing mock-interview sessions, Hence students are Getting out of their interview fear.
ReplyDelete