Hi,
I wish to have the resource to programme the row and column layout.  Further, for the information updated, how can I host the data and let my application to retrieve the information or data?  Thanks for your concern.
Looking forward for your feedbacks.
WC

There are two common ways to display information as rows and columns.  The first is the GridLayout that I described in the previous post.  Or there’s a TableLayout, which imposes a row and column format on the contents.

For example:-

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*" >
  <TableRow>
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="abcedfghij" />
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="klmn" />
  </TableRow>
  <TableRow>
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="opqr" />
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="stuvwxyz" />
  </TableRow>
</TableLayout>

Inside the <TableLayout>, we define each row’s contents inside <TableRow> tags.  Notice the … android:stretchColumns=”*”.  This means pad all the columns out so that the table takes up all the horizontal space.

But suppose that you don’t know how many rows your table has.  If your application is downloading data, you might now know how many rows you need to generate.  In this case, you might dynamically create your table in Java.

package com.danielfreeman.android;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class HelloDynamicTable extends Activity {

	protected static final String[][] DATA = {{"Fred","Bloggs","32"},{"Jane","Doh","28"},{"Peter","Smith","35"}};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TableLayout table = new TableLayout(this);
        table.setLayoutParams(new TableLayout.LayoutParams(
        		TableLayout.LayoutParams.FILL_PARENT,
        		TableLayout.LayoutParams.WRAP_CONTENT)
        );
        table.setStretchAllColumns(true);

        for (String[] record : DATA) {

        	TableRow row = new TableRow(this);
        	row.setLayoutParams(new TableRow.LayoutParams(
            		TableRow.LayoutParams.FILL_PARENT,
            		TableRow.LayoutParams.WRAP_CONTENT)
            );

            for (String field : record) {
            	TextView column = new TextView(this);
            	column.setLayoutParams(new TableRow.LayoutParams(
            			TableRow.LayoutParams.FILL_PARENT,
            			TableRow.LayoutParams.WRAP_CONTENT)
                );
            	column.setText(field);
            	row.addView(column);
            }

            table.addView(row);
        }

        setContentView(table);
    }
}

You’ve asked about hosting data too. Do you mean on the server?  On the course, you will have learnt about obtaining and parsing XML data from the server.  My groups did an exercise using the SAX parser.  I think Mark’s group looked at the DOM parser.  In your application, are you also uploading changes, and storing them in a database on the server?  What exactly will your application do?

Perhaps this RSS reader tutorial will help:

http://www.helloandroid.com/tutorials/newsdroid-rss-reader

Advertisements