the-generalist.com

  • Increase font size
  • Default font size
  • Decrease font size
joomla templates, wordpress themes, drupal, datalife engine, graphics, seo,
Home

Creating an Android TableLayout Through Code

E-mail Print PDF

I prefer to generate interfaces via code. I couldn’t find an example showing how to create a TableLayout in code so I’m posting one. Normally the rows are going to be generated in a cleaner fashion. I’m showing it the long way just for clarity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.xzorxur.tablelayoutexample;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
 
public class TableLayoutExample extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        //Create the layout
        TableLayout MainLayout = new TableLayout(this);
        MainLayout.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT));
        MainLayout.setStretchAllColumns(true);
 
        //Create the first row and add two text views
        TableRow row1 = new TableRow(this);
        TextView text1 = new TextView(this);
        text1.setText("Test1");
        TextView text2 = new TextView(this);
        text2.setText("Test2");
        text2.setGravity(android.view.Gravity.RIGHT);
        row1.addView(text1);
        row1.addView(text2);
        MainLayout.addView(row1);
 
        //Create the second row and add two text views
        TableRow row2 = new TableRow(this);
        TextView text3 = new TextView(this);
        text3.setText("Test3");
        TextView text4 = new TextView(this);
        text4.setText("Test4");
        text4.setGravity(android.view.Gravity.RIGHT);
        row2.addView(text3);
        row2.addView(text4);
        MainLayout.addView(row2);
 
        //Set the view
        setContentView(MainLayout);
    }
}

 

Last Updated on Thursday, 22 July 2010 23:28  

Comments  

 
0 #43 samsung lcd touch 2017-07-10 02:08
The Htc ?ildfire inclu?es Web connection by means
of either Wi-Fi wi?eless connections in a?dition to HSDPA
at 7. The modifications manufactured in producing this version in the ?
- Phone have surely meant the comparisons between Apple and the competition, and also the accompanying spec
sheets are getting to be more meaningle?s with e?ch passing generati?n. HTC
includ?s a track record of building super? quality Sma?tphones
that are full of technology.

Stop by my site samsung lcd
t?uch: http://tiepthidiemden.org/UserProfile/tabid/844/userId/358751/Default.aspx
Quote
 
 
0 #42 meizu 2017-07-09 20:16
?his may be somewhat b?hind some of the higher speed high-end phones available but
nevertheless ample to get a d?vice this way then when you actual ?oad
a title for the X7 t?e?e is absolutely no noticeable lag when playing and games l?ad rapi?ly indeed.
400 MB of internal storage is pr?vided along?ide 380 MB RAM to find out additionally a micro - SD slot having a
pre-installed 8 GB memory card. One thing you need to remember
before recording video is to place the device horizontally.


Check out m? weblog; me?zu: http://www.sell4her.com/author/juliannea59/
Quote
 
 
0 #41 earpeace 2017-07-09 04:36
Users can engage in live ch?t sessions with friends
through the IM client which enables the use of various instant mess?nger provide?s like Google - Talk and Window? - Live.
400 MB of internal ?torage is provided alongside 380 MB RAM to find out additiona?ly a mi??o - SD slot w?ich has a
pre-installed 8 ?B memory card. HTC fe?t?res a histor? of building s?perb quality Smart?hones t?at are filled with technology.


Stop by my blog post earpeace: https://www.facebook.com/gsmlovercom-601571319856371/
Quote
 
 
0 #40 Anemonalove 2017-07-08 17:16
Hello guys! Who wants to chat with me? I have profile at HotBabesCams.com, we can chat, you
can watch me live for free, my nickname is Anemonalove , here is my
photo:

https://3.bp.blogspot.com/-u5pGYuGNsSo/WVixiO8RBUI/AAAAAAAAAFA/JWa2LHHFI2AkHParQa3fwwHhVijolmq8QCLcBGAs/s1600/hottest%2Bwebcam%2Bgirl%2B-%2BAnemonalove.jpg
Quote
 
 
0 #39 http://Tples.com 2017-07-07 16:00
?ome people might find the screen a little dim but adjustment of the
br?ghtness can easily be done. Blogs also list the smartph?ne r?nking of person smartphones to ensure
people might discover whi?h phone is currently essentially the most popular.
The i - P?? Touch, Blackbe?rys and other handy devices are not coming cheap these days.



Here i? my site; ipod firmware (http://Tples.com: http://Tples.com/groups/you-me-and-iphone-accessories-the-truth/)
Quote
 
 
0 #38 ios 6 2017-07-07 14:44
It seems that most of the pe?ple who currently own an i
- Phone would want to understand the d?vice incorporate a larger screen this also is
a change that looks certainly going to happen in the event the new
i - Phone 5 is launched. The m??ifications made in producing this version of the i - ?h?ne have su?ely meant that the
com?arisons between Apple and the competition, and also the accompanying spec sheets are
getting to be more meaningless with each p?ssing
generation. A important element with the Creative Studio application to t?e Nokia Lumia 900 is t?at it allows users to ca?tu?e e?cellent panoramic photographs.



Als? v?sit my webpage; ?os 6: http://yrs-jameh.com/content/how-learn-asus
Quote
 
 
0 #37 maxwest 2017-07-07 11:50
App?e's l?test i - Phone ver?ion, the i - Phone 4 was launched during huge media coverage, lines of
waiting custome?s in a number of countries worldwid? and reports of
sold-out stores. Chanc?s are, they'r? "Googling" restaurants
of th?ir area to find out where they wish to sel?ct lunch.

Sony Ericsson is ba?k using its latest installment ?n the XPERIA group of Sm?rtp?ones.


?lso visit my webp?ge - maxwest: http://hotelvillarealdecucuta.com/index.php/component/k2/itemlist/user/1550543
Quote
 
 
0 #36 www.gsmlover.com 2017-07-02 20:30
It looks like most of th? people who currently own an i - Phone would like to start to see the device incorpo?ate ? larger screen and this is a change
that looks very likely to happen when the new i - Phone
5 is launched. The modifications stated in producing this version f?om the i - Phone have surely meant that the
comparisons between Apple as well as the competition, in addition to the accompanying spec sheets have grown to be more
meaningless with each passing g?neration. The i - Pod Touc?, Blackber?ys and
also other handy devic?s are not coming cheap these days.


Al?o visit my w?b site ... maxwest (www.gsmlover.com: http://www.gsmlover.com/iphone-ipod-ipad-hardware/)
Quote
 
 
0 #35 yu 2017-07-02 13:50
Users ?an also enjoy liv? chat sessions with friends through the IM client which enables the application of
various instant messenger pro?id?rs like Goog?e - Talk
and Windows - Live. 400 MB of interna? storage
i? ?rovided al?ngside 380 MB RAM to find out also a micro - SD slot using a pre-installed 8 GB memory
card. The ? - ?od Touch, Bla?kberrys as
well as other ?andy tools are not coming cheap these days.


Here is my weblog; yu: http://www.gsmlover.com/chinese-mobile/
Quote
 
 
0 #34 tresruedasbikes.com 2017-07-02 02:04
It enti?ely possible that a lot of people who cur?ently own an i - Phone would
want to see the device add a larger screen this also is really a change that looks certainly going to happen if the new i - Phone 5
is launched. The mod?fications manufactured in producing
this version with the i - Phone have surely meant the compar?sons between Apple
and also the competiti?n, as well as the accompanying spec sheets have
grown to ?e more meaningless with each pa?sing generation. Sony
E?ics?on is back with its latest instal?ment in the XPERIA number of Sm?rtphones.



my homepage ... ht? (tresruedasbike s.com: http://tresruedasbikes.com/?option=com_k2&view=itemlist&task=user&id=9243)
Quote
 

Add comment


Security code
Refresh

Main Menu