Android-Activity program dynamically generates a table layout manager

Source: Internet
Author: User

Android-Activity program dynamically generates a table layout manager

The. java code is as follows:

 

Package org. lxh. demo; import android. app. activity; import android. OS. bundle; import android. view. viewGroup; import android. widget. tableLayout; import android. widget. tableRow; import android. widget. textView; public class MyTableLayoutDemo extends Activity {private String titleData [] [] = new String [] [] {ID, name, EMAIL, address}, {01, Li, xiaoli@163.com, beijing },{ 02, Xiaozhang, xiaozhang@163.com, Tianjin };// define the data to be displayed @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); TableLayout layout = new TableLayout (this); // defines the table layout TableLayout. layoutParams layoutParam = new TableLayout. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. FILL_PARENT); // defines the parameters of the layout manager // layout. setBackgroundResource (R. drawable. mldn_logo); // defines the background image for (int x = 0; x <this. titleData. length; x ++) {// cyclically set the table row TableRow row = new TableRow (this); // defines the table row for (int y = 0; y <this. titleData [x]. length; y ++) {TextView text = new TextView (this); text. setText (this. titleData [x] [y]); // sets the text content row. addView (text, y); // Add a number} layout. addView (row); // Add several table rows to the table} super. setContentView (layout, layoutParam); // set display }}


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.