1. Download our Official Android App: Forums for Android!

TableLayout programming

Discussion in 'Android Lounge' started by ateneouw, Jan 9, 2019.

  1. ateneouw

    ateneouw Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jan 9, 2019

    Jan 9, 2019
    1
    0
    5
    My question is how do i access TableLayout as indexes.
    If i do:

    TableLayout table = (TableLayout) findViewById(R.id.MyTable);

    i get the control in "table". But how do i access rows and colums? Or if i want to create a new row programmatically, how do i do?

    Thanks in advance.
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    8,136
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    8,136
    11,931
    1,988
    Male
    Software developer
    South West of England
    There's some code here which adds a new table row dynamically

    https://stackoverflow.com/questions...ly-adding-tablerow-to-tablelayout-not-working

    Code (Text):
    1.  
    2. /* Find Tablelayout defined in main.xml */
    3. TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines);
    4. /* Create a new row to be added. */
    5. TableRow tr = new TableRow(this);
    6. tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    7. /* Create a Button to be the row-content. */
    8. Button b = new Button(this);
    9. b.setText("Dynamic Button");
    10. b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
    11. /* Add Button to row. */
    12. tr.addView(b);
    13. /* Add row to TableLayout. */
    14. //tr.setBackgroundResource(R.drawable.sf_gradient_03);
    15. tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    16.  
     

Share This Page

Loading...