Fundamentals
Introduction
1st Android Application

OOPS Concepts
Class
Object
Abstraction
Encapsulation

Polymorphism
Inheritance
Message Passing
Dynamic Binding

UI Controls
TextView
Button
Toggle Button
CheckBox
Radio Button
Spinner
ProgressBar
SeekBar
RadioGroup
RatingBar
Switch
EditText
AutoComplete
TextView

MultiAutoComplete
TextView

ImageView
ImageButton
Gallery
MediaPlayer
VideoView
MediaController

TimePicker
DatePicker
CalendarView
Chronometer
Analog Clock
Digital Clock

Layouts
LinearLayout
RelativeLayout
GridLayout
TableLayout
FrameLayout
Fragment

Composite
ListView
ExpandableListView
GridView
ScrollView
SearchView
Sliding Drawer
Tab Widget
WebView

Transitions
Image Switcher
StackView
TextSwitcher
ViewAnimator
View Flipper
View Switcher

Advanced
Request Focus
View
View Stub
TextureView
Gesture Overlay View

SurfaceView
NumberPicker
Zoom Button
Zoom Controls
AbsoluteLayout

Database
SharedPreference
SQLite DB
MySQL DB

Webservices
Check HttpURLConnection
Single Webservice Call
Multi Webservice Call
ListView from Webservice
SQLite from Webservice
Data from Database

Telephone Manager
IMEI
IMSI
Phone Type
Sim Type
Network Type

Content Providers
Contact Provider
BookMark Provider
Own Provider


Message & Networking
Send SMS
SMS with Reports
Group SMS

Send E-Mail
Download Binary Data


Location Based Service
Display Google Map
Events with Google Map

Android Services
Create Service
Create Longtime Service

Asynchronous Task
Repeating Services
IntentService

Activity from a Service
Bind Activity to Service


Sample Projects
HMS
CNB
Login Screen
Camera Event
Browse Option
QR Code Events
Accelerometer Sensor
EditText from Spinner

Android Tab Widget

  1. Tab Widget Creation in Android

Note                     Download ADT Plugin Here.
Here I am using,
OS : Linux (Ubuntu 12.04)
Eclipse : Juno (Version 4.2.0)
Android API Level : 3 to 'n' as per need
Emulator API Level : It will be displayed in output image

A. Tab Widget Creation in Android


Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.

Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:padding="11dp"
        android:text="1st Year" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_marginTop="20dp"
        android:padding="11dp"
        android:layout_centerHorizontal="true"
        android:text="2nd Year" />
    
</RelativeLayout>

Step 3 : Open res -> layout -> list_view.xml and add following code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
	<ListView  android:id="@+id/list"
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content"
	    android:background="#000000" >
	</ListView>
</LinearLayout>

Step 4 : Open res -> layout -> list_item.xml and add following code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" 
	android:layout_height="wrap_content"
	android:orientation="horizontal">
	
	<TextView android:id="@+id/demo" 
	    android:text="TEST" 
	    android:layout_gravity="center_vertical"
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content" 
	    android:paddingTop="20dp"
	    android:paddingBottom="20dp"
	    android:paddingLeft="35dp"
	    android:textColor="#7CFC00"
	    android:textSize="15dp"
	    android:layout_weight="10">
	    
	</TextView>
</LinearLayout>

Step 5 : Open src -> package -> MainActivity.java and add following code :

package balaji.tabwidget_creation;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
 
public class MainActivity extends Activity {
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final Button first=(Button) findViewById(R.id.button1);
        final Button second=(Button) findViewById(R.id.button2);
     
        first.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(final View v) {
			// TODO Auto-generated method stub
			final Intent i=new Intent(MainActivity.this,First.class);
			MainActivity.this.startActivity(i);			
		}
	});
        
        second.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(final View v) {
			// TODO Auto-generated method stub
			final Intent i=new Intent(MainActivity.this,Second.class);
			MainActivity.this.startActivity(i);			
		}
	});
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }    
}

Step 6 : Open src -> package -> First.java and add following code :

package balaji.tabwidget_creation;
 
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
 
public class First extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        final Resources res = getResources();
        final TabHost tabHost = getTabHost();
	        
        final Intent i1 = new Intent().setClass(this, A_Section.class);
        final TabSpec oneSpec = tabHost.newTabSpec("A").setIndicator("A Section",
        		res.getDrawable(R.drawable.ic_action_search))
        		.setContent(i1);
        tabHost.addTab(oneSpec);
        
        final Intent i2 = new Intent().setClass(this, B_Section.class);
        final TabSpec twoSpec = tabHost.newTabSpec("B").setIndicator("B Section",
        		res.getDrawable(R.drawable.ic_action_search))
        		.setContent(i2);
        tabHost.addTab(twoSpec);

        tabHost.setCurrentTab(2);
    }
}

Step 7 : Open src -> package -> Second.java and add following code :

package balaji.tabwidget_creation;
 
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
 
public class Second extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        final Resources res = getResources();
        final TabHost tabHost = getTabHost();
	        
        final Intent i1 = new Intent().setClass(this, A_Section.class);
        final TabSpec oneSpec = tabHost.newTabSpec("A").setIndicator("A Section",
        		res.getDrawable(R.drawable.ic_action_search))
        		.setContent(i1);
        tabHost.addTab(oneSpec);
        
        final Intent i2 = new Intent().setClass(this, B_Section.class);
        final TabSpec twoSpec = tabHost.newTabSpec("B").setIndicator("B Section",
        		res.getDrawable(R.drawable.ic_action_search))
        		.setContent(i2);
        tabHost.addTab(twoSpec);

        tabHost.setCurrentTab(2);
    }
}

Step 8 : Open src -> package -> A_Section.java and add following code :

package balaji.tabwidget_creation;
 
public class A_Section extends List_Activity
{
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "A";
	}	
}

Step 9 : Open src -> package -> B_Section.java and add following code :

package balaji.tabwidget_creation;
 
public class B_Section extends List_Activity{
 
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "B";
	}
}

Step 10 : Open src -> package -> List_Activity.java and add following code :

package balaji.tabwidget_creation;
 
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
 
public abstract class List_Activity extends Activity {

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        final ArrayAdapter<String> adp = new ArrayAdapter<String>(this, 
        		R.layout.list_item, R.id.demo);
        
        for (int i = 0; i < 15; i++) {
            adp.add(getName() + " : " + i);
        }
        setContentView(R.layout.list_view);
        final ListView listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(adp);
        
        listView.setOnItemClickListener(new OnItemClickListener() {
 
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Toast.makeText(getApplicationContext(), adp.getItem(arg2),
				Toast.LENGTH_SHORT).show();
		}
	});
    }
 
    public abstract String getName();
}

Step 11 : Open AndroidManifest.xml and add following code :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.tabwidget_creation"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".First">
          
        </activity>
        <activity
            android:name=".Second">
           
        </activity>
        <activity
            android:name=".A_Section"
            android:theme="@android:style/Theme.NoTitleBar" />
        <activity
            android:name=".B_Section"
            android:theme="@android:style/Theme.NoTitleBar" />
    </application>
 
</manifest>

Step 12 : Open res ->values ->strings.xml and add following code :

<resources>
 
    <string name="app_name">TabWidget_Creation</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
 
</resources>

Step 13 : Our output will be like this :


Output


Output


Output









SHARE THIS PAGE



product 2

product 3

product 4

Feedbacks : balaji.scz@gmail.com