100KDroid : TableLayout in Android

Hello World!!!!!

TableLayout in Android

Using Table Layout in Android:: 
This Tutorial describes how to use TableLayout in Android.In this example we have created a Form using TableLayout,which you can modify according to your requirements. For this tutorial Android 17 used. 

What is TableLayout and How we can use it in Android? TableLayout:-A layout that arranges its children into rows and columns. A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML. 


Different Types of TableLayout which you can create from the TableLayout::

          

Source Code TableLayout Example::

1.Create Android Application Project named it as a TableLayout in Eclipse. 

2.In this we have a java class in src folder and an activity file which is by default activity_main.xml located in layout folder under res folder. 
3.Our next file will be AndroidManifest.xml file located in main folder. 
4.Below is the code given for all these three files i.e 
     4.1. First one is for activity_main.xml .
     4.2. Second one is for MainActivity.java . 
     4.3. Third one is for AndroidManifest.xml . 4.4. And in Last we have the output .


activity_main.xml::

activity_main.xml :: your main xml file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1" >

        <TableRow>

            <TextView android:text="First Name" />

            <EditText 
                android:hint="Hello">
                <requestFocus/>
                </EditText>
        </TableRow>

        <TableRow>

            <TextView android:text="Last Name" />

            <EditText
                android:imeOptions="actionSend"
                android:inputType="text|textEmailAddress" />
        </TableRow>

        <TableRow>

            <TextView android:text="Contact Number :" />

            <EditText
                android:hint="+91-"
                android:imeOptions="actionDone"
                android:inputType="number|numberSigned|numberDecimal" />

        </TableRow>

        <TableRow>

            <TextView android:text="Email Address :" />

            <EditText android:inputType="date" />
        </TableRow>

        <TableRow>

            <TextView android:text="Description :" />

            <EditText
                android:gravity="top"
                android:inputType="text|textMultiLine|textAutoCorrect"
                android:minLines="3" />
        </TableRow>
    </TableLayout>

</ScrollView>
MainActivity.java::
MainActivity.java :: your main java file
package com.shokeen.tablelayout;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

AndroidManifest.xml::
AndroidManifest.xml :: your manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.shokeen.tablelayout"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.shokeen.tablelayout.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Output::
Output of the TableLayout Android Project... ☺ ☺ ☺ ☺☻ ☻ ☻
Table Layout Output......!!!

No comments:

Post a Comment

Copyright © 100KDroid Urang-kurai