You are on page 1of 51




(၁) Hello eclipse world! open Application

Project create File>New>Android Application Project

Next Minimum Required SDK Android version 2.2 ppli ion 2.2 install sdk version

click application 3.0

Browse (application Next ) logo

com/htarhtarlwintun .com www.htarhtarlwin.facebook.blogspot.facebook.

Next .

com/htarhtarlwintun .Install/Upgrade ( click install ) www.blogspot.facebook. www.facebook.Accept All Install click . .2 ) USB create USB Cable check htarhtarlwin.project (1) debugging (2) (3) (4) OK Phone Run>Run device (Android version 2. ) .com/htarhtarlwintun www.(5) (6) Phone menu Hello world! application (Settings>Applications>Manage ) Droid1 Hello World! application touch uninstall applications pk il bin Droid1.apk install o ( htarhtarlwin.blogspot.

facebook.facebook.l on ( click ) (၁) Run on Emulator Android android ( /tablet/note) (emulator) ( ) run emulator run run run project real device emulator ppli ion device www.

com/htarhtarlwintun www.facebook.Android Virtual Device Manager eclipse tool ool Android Virtual Device Manager click .

facebook.RAM 1024 512 or 256 or 128 ) .

com/groups/htarhtarlwin www.

com/htarhtarlwintun www.facebook.HHl Start click www.

com .eclipse application Hello Run world! ( ) emulator www.

import android. import android.droid1>DroidActivity.example.Menu.//***** public class DroidActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { Explorer create Droid1 package www. import .droid1.(၁) ( ) coding application run Hello World! Eclipse Package Droid1>src>com.facebook.blogspot. import android.example.

inflate( www.setText("Hello! I'm Dr. } } phone Emulator run run run (၁) Discussion tutorial Android SDK htarhtarlwin. Htar Htar Lwin"). return true.onCreate(savedInstanceState) . menu).//***** } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater(). TextView tv = new TextView(this).//***** tv.super.facebook.//***** setContentView(tv).main.facebook.

facebook.facebook.blogspot.install install i k D sdk drive Start l check number of packages) Android www.2 ( (Android SDK install download ool Install * packages SDK pl click Manager om pl om check download (* = ) sdk folder ) SDK Manager .

com www.blogspot.2 ) User Interface ( ool create a new Android project tool Next click click 3.facebook.eclipse Eclipse IDE download unzip eclipse Eclipse install Project create command line eclipse tools eclipse create m l o application run run run n oi ppli ion ADT Plugin (၁) ( SDK .com/htarhtarlwintun www.facebook.0 htarhtarlwin. .com www.blogspot.( Next htarhtarlwin. .facebook. .com www.facebook. .facebook.

com/apk/res/android" xmlns:tools="http://schemas.facebook.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.xml o copy <?xml version=" www.facebook.MyApp2>res>layout>activity_main.xml o <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">My First App</string> <string name="edit_message">Enter a message</string> <string name="button_send">Send</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string> </resources>" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /> </LinearLayout> MyApp2>values> .

Run Button run apk (coding ( ) emulator run Textbox in install ) .com www. .com www.(၁) ( ) coding www.facebook.

com/groups/htarhtarlwin .com/tools" android:layout_width="match_parent" android:layout_height="match_parent" screen android:orientation="horizontal" textbox button width and height Textbox <EditText android:id="@+id/edit_message" android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content" textbox width and height android:hint="@string/edit_message" /> button <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" /> </LinearLayout>" xmlns:tools="http://schemas.0" encoding="utf-8"?> <LinearLayout xmlns:android=" button textbox button layout For layout <?xml version=" www.

blogspot.facebook.xml Add android:onClick="sendMessage" as follow: <Button android:layout_width="wrap_content" htarhtarlwin.0" encoding="utf-8"?> <resources> <string name="app_name">My First App</string> ppli ppli “En ppli ion ion m ion n g ” n on ing “ n ” n m o string <string name="edit_message">Enter a message</string> <string name="button_send">Send</string> <string name="menu_settings">Settings</string> <string name="title_activity_main">MainActivity</string> </resources> (၁) ( ) textbox button display ( ) MyApp button project create textbox Open MyApp>res>layout> .com/htarhtarlwintun www.<?xml version="1.

setContentView( Add these codes.view.putExtra( .com/htarhtarlwintun www. intent.blogspot.layout.os.toString().Intent.view. message). startActivity(intent).myfirstapp. } @Override public void onCreate(Bundle savedInstanceState) { super.Menu.myfirstapp.activity_main). EditText editText = (EditText) findViewById(R.Activity. public class MainActivity extends Activity { public final static String EXTRA_MESSAGE = "com. DisplayMessageActivity.EditText. import android. import android. import android. package com.content.widget.MESSAGE""wrap_content" android:text="@string/button_send" n oi on li k n g ) Open MyApp>src>MainActivity.edit_message).com www.facebook. /** Called when the user clicks the Send button */ public void sendMessage(View view) { Intent intent = new Intent(this. htarhtarlwin. import String message = editText.Bundle.class). import android.getText(). import android.View.

menu). press Ctrl + Shift + O to import missing classes Now you need to create the DisplayMessageActivity class in order for this to www. return true.blogspot. www.} @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().example.facebook. 3. Fill in the activity details: o o o o o o Project: MyFirstApp Activity Name: DisplayMessageActivity Layout Name: activity_display_message Navigation Type: None Hierarchial Parent: com. Click Next.MainActivity Title: My Message Click Finish. In the window that appears. Click New in the toolbar. } } Tip: In Eclipse.inflate( . open the Android folder and select Android Activity. 4. To create DisplayMessageActivity class 1.myfirstapp. Select BlankActivity and click Next.

com/htarhtarlwintun www. Add it to the manifest htarhtarlwin. The class should look like this: public class DisplayMessageActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super. The new activity wizard in Eclipse.onCreate(savedInstanceState). setContentView(R.layout.activity_display_message).blogspot. } } All subclasses of Activity must implement the onCreate() method.facebook. It is where you must define the activity layout and where you should perform initial setup for the activity components. Open the . The system calls this when creating a new instance of the activity. There's also an implemtation of the onCreateOptionsMenu() method. but you won't need it for this app so you can remove it. The class already includes an implementation of the required onCreate() method.Figure file.facebook.

In h i pl y g i iy l ’ onCreate() method.blogspot.facebook. The complete onCreate() method for DisplayMessageActivity now looks like this: htarhtarlwin.example. You used the Eclipse tools to create the activity. <activity android:name=". it creates a default entry. You can get the Intent that started your activity by calling getIntent() and retrieve the data contained within it.facebook. using an <activity> element.MainActivity" /> </activity> </application> Receive the Intent Every Activity is invoked by an www.xml... String message = intent.PARENT_ACTIVITY" android:value="com. AndroidManifest. regardless of how the user navigated there.EXTRA_MESSAGE).You must declare all activities in your manifest file. Then add the TextView to setContentView()..getStringExtra(MainActivity. > . create a TextView widget and set the text using setText().DisplayMessageActivity" android:label="@string/title_activity_display_message" > <meta-data android:name=" h oo i o h i i y’ l yo yp ing i www.myfirstapp. get the intent and extract the message delivered by MainActivity: Intent intent = getIntent(). It should look like this: <application . Display the Message To show the message on the

com/htarhtarlwintun www.blogspot. // Create the text view TextView textView = new TextView(this). textView.setText(message). import android.widget.getStringExtra(MainActivity.onCreate(savedInstanceState).EXTRA_MESSAGE). textView. // Get the message from the intent Intent intent = getIntent(). DisplayMessageActivity class looks like this: package com.os.facebook. import android. import // Set the text view as the activity layout setContentView(textView). String message = intent.setTextSize(40). htarhtarlwin. import .example. public class DisplayMessageActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.Activity.onCreate(savedInstanceState).com www.@Override public void onCreate(Bundle savedInstanceState) { super. } Finally.content.Intent.TextView.

When it opens.EXTRA_MESSAGE).getStringExtra(MainActivity. and the message appears on the second .blogspot. String message = www.// Get the message from the intent Intent intent = getIntent().facebook. } } You can now run the app. textView. htarhtarlwin.setText(message). // Create the text view TextView textView = new TextView(this).com/htarhtarlwintun www. // Set the text view as the activity layout setContentView(textView). click Send.facebook.setTextSize(40). textView. type a message in the text field.

facebook. (၁၁) www.0.facebook. Both activities in the final app.blogspot.Figure 2. running on Android .

com/groups/htarhtarlwin .blogspot.setText(new Date(). import android. import android.skeleton. btn.example.View.onCreate(icicle).Date. } public void onClick(View view) { updateTime().toString()).view.facebook.setOnClickListener(this).util. htarhtarlwin.widget.Button. import file activity name o Now o package setContentView(btn).Activity.facebook.OnClickListener { Button btn.n oi application i project current time create display Project name skeleton www. updateTime(). import java. public class Now extends Activity implements View.os.Bundle. @Override public void onCreate(Bundle icicle) { super. import android. } private void updateTime() { www. btn = new Button(this).

program android-specific class l android import package public class Now extends Activity implements View.Bundle.Activity button (btn) android widget I l m n base class extend hold widget extend . import android. Activity Now base class program (Button application i g ) on implement @Override htarhtarlwin.Activity.facebook.view. import android.util.View.OnClickListener { Button btn. import java.skeleton.facebook.Button. import android.blogspot.} } Discussion package li k Now activity OnClickListener trap View p li l Now android. package declare import www.Date.

public void onCreate(Bundle icicle) { .setText(new Date(). setContentView(btn).toString()). btn.setOnClickListener(this).com www. button setOnclickListener() updateTime() button method program current run time display instance create instance button li k onCreate() method setContentVi public void onClick(View view) { updateTime().facebook.blogspot.facebook. btn = new Button(this). www. so the stock Android activity initialization can be done.onCreate(icicle). updateTime(). } Activity invoke The first thing you should do is chain upward to the superclass. } Button invoke click onClickListener instance button updateTime method button configure ll click onClick() method private void updateTime() { btn.

} Activity open button label button current click time setText() program tap current time run tap onCreate() method run updateTime() run tap current n run time im .com/htarhtarlwintun www.

main or R.blogspot.facebook.xml button create layout name o file i g generate yl text “ ol ” ol aapt tool l yo .layout.(၁၁) i g create o il XML-based layout widget on in o ol l m n i g on in Button element n oi l yo file layout p op attribute value button i attribute p op i l yo relationship widget relationship l yo il l yo activity attach htarhtarlwin.button xml code project NowRedux main l yo run button button tap ml www.

view.button <RelativeLayout xmlns:android=""> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </RelativeLayout> XML layout file button create xmlns:android="" Root element Android XML l m n name space declaration android:id="@+id/button" button jave identifier element java l m n Button Button Android-supplied XML element widget widget" xmlns:tools=" Button class name subclass i code code android:id attribute i inherit namespace root declare hil n .

facebook. import android.Date.View.Activity.example. j package com. import . import android.os.xml layout file back setContentView( www.view. import statement button findViewById().blogspot.layout.layouts.widget.main).java file onCreate() call NowRedux.MyWidget android:layout_width="wrap_content" android:layout_height="wrap_content" button android:text="" button space button main.create com. o text width height full package declaration XML java code code res/layout access NowRedux.facebook. import android.

@Override public void onCreate(Bundle icicle) { super.facebook. btn.blogspot. btn=(Button)findViewById( www. } private void updateTime() { btn. } public void onClick(View view) { updateTime().layout.setText(new Date().button).id.onCreate(icicle). updateTime().main).facebook. setContentView(R.setOnClickListener(this).OnClickListener { Button btn.toString()). } } run button program button tap XML code .com www.public class NowRedux extends Activity implements View.

button Assigning Labels Label android TextView textbox user box user edit .facebook. label.(၁၁) Employing Basic Widget i g Widget www.blogspot. www.label Label create TextView element button property create textbox TextView instance XML layout file create android: text text p op i android:typeface monospace android:textstyle bold.xml run <TextView xmlns:android="http://schemas. italic or bold and italic android:textColor RGB project Label .com/apk/res/android" android:id="@+id/TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="You were expecting something profound" /> o p activity name file create main o hex format htarhtarlwin.

blogspot.Fields of . Or Other www. Edit Text Edit Text widget p op i android:autoText auto spelling android:capitalize capital o android:digits igi TextView subclass Edit Text htarhtarlwin.facebook. single line or multiline android:numeric numeric-only input android:password password input android:phoneNumber phon n m Field FieldDemo file project create activity name www. import android.basic. htarhtarlwin.facebook.0" encoding="utf-8"?> <EditText xmlns:android="http://schemas. import" android:id="@+id/field" android:layout width="fill parent" android:layout height="fill parent" android:singleLine="false" /> android:singleLine l o package com.xml o <?xml version="1.commonsware.os.

import android. You may " + "obtain a copy of the License at " + "http://www.onCreate(icicle).blogspot.setText("Licensed under the Apache License.EditText.0 " + "(the \"License\"). setContentView(R.0"). public class FieldDemo extends Activity { @Override public void onCreate(Bundle icicle) { Version 2. fld. EditText fld=(EditText)findViewById(R.apache.widget. you may not use this file " + "except in compliance with the } } Run .field).com/htarhtarlwintun www.main).

com/groups/htarhtarlwin .com/htarhtarlwintun www.(၁၁) www.blogspot.facebook.facebook.