how to write android application (2 to 12)

68
Android Application () ကကက htarhtarlwin.blogspot.com ကကကကကကကကကကက Android Application ကကကကကကက () Hello world! ကကကကကကကကကကက Application ကကကကကကကကကက ကကကကကကကကကက eclipse ကကက open ကကကကကကက ကကကကကကကကကကကကကကကကကက htarhtarlwin.blogspot.com www.facebook.com/htarhtarlwintun www.facebook.com/groups/htarhtarlwin

Upload: wunna-aung-shattereddreams

Post on 28-Oct-2015

40 views

Category:

Documents


3 download

DESCRIPTION

About how to write android app

TRANSCRIPT

Page 1: How to Write Android Application (2 to 12)

Android Application (၁) က�� htarhtarlwin.blogspot.com မ�ၾကညပ�။

Android Application ေ�ရနည� (၂)

Hello world! လ��႕ေ�ပၚမယ�� Application တစခေ��႕ေရၾကညပ�႕ေ�အင�။eclipse က�� open လ�ပ။

႕ေအက� ပ��႕ေပၚလမယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 2: How to Write Android Application (2 to 12)

Project create လ�ပဘပ�ပဘ���အတြတက�File>New>Android Application Project

အထကအတ��င� ျ"ဖညပ�$%က�"ပ& Next က�� click ပ။ Minimum Required SDK

က�� 2.2 ဒဒ ထခ(�ရင�ဒ& application က�� Android version 2.2 န(�အထက+� install လ� ပ�ငမယ�။ application ျ ႕ေရတ(�အခသ��မယ�� sdk version ႕ေကတ 3.0 လ���သတ+�တ- ��ကတယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 3: How to Write Android Application (2 to 12)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 4: How to Write Android Application (2 to 12)

Browse က��$ဖင��"ပ&ပ��က��မ�မ�စခေ�တ. က�/က�႕ေရြရခ1ယ�ငတယ�။ (application logo က�� ဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒ မ�မ�ပ��န(�"ဖစခေ�1င�င�႕ေပ�။မဟ�တ� င�႕ေတဒ&တ��င� Next သပ။)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 5: How to Write Android Application (2 to 12)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 6: How to Write Android Application (2 to 12)

အထက��အတ��င�ဖညပ�$%က�"ပ& Next

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 7: How to Write Android Application (2 to 12)

ဒ ဒ ဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ပထမဆ��အၾက�+%လ�ပဘပ4ဆ��ရင�အထက ပ��အတ��င�ပၚလမယ�။ Install/Upgrade

က�� click ပ။ ( ဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ အင4နတဖြတ6င�78ရပမယ�။ဒ&အခ1�န �႕ေလမ�တ။ install လ�ပ�"ပ&ရင�"ပနပ�တ�လ���ရပပ&။)

Accept All က��႕ေရြရပ& Install က�� click ပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 8: How to Write Android Application (2 to 12)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 9: How to Write Android Application (2 to 12)

အထကပ��အတ��င� project တစခေ��က�� create လ�ပ�"ပ&ဖစခေလ�မ�+ယ�။(1) ဖ�န � (Android version 2.2 :�င�7;ထက�) မ� USB debugging က��

check လ�ပဘပ8ပ။(2) Phone က�� တြကနပ1<တန(႔ USB Cable သ��ပ&ခ1�တ။(3) Run>Run က��ပ။(4) ဒဒဒဒဒဒဒ ႕ေအက��အတ��င�မ�မ�ရ(� device က�� ျ႕ေရြရပ& OK လ�ပ။

(5) Phone မ�ၾကညပ�>-?��က။ Hello World! ဆ��"ပ&တြတ�ပမယ�။(6) ဖ�န �menu မ�ၾကညပ�။ Droid1 ဆ��တ(� application တစခေ��႕ေတြတ�မယ�။

အ(ဒက�� touch ဒဒဒဒဒဒဒဒ ဒဒဒ လ�ပ။ခ�႕ေနတြတ�သလ�� Hello world! ဒဒဆ��တတြတ�မယ�။အ" ခ application မ1က(�သ��� uninstall ဒဒဒဒဒဒ ဒဒဒလ�7ပ-?��ကလ�ပ�ပဘင@ပဘညပ�။လ�7ပ. ကညပ�� ပ။ (Settings>Applications>Manage applications မ�တြသလ�ပ။)

apk file ျ႕ေလကဘယ+�ရ��မ�လ(bin က��$6င�။ Droid1.apk ဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဆ��တ(� ဖ��င�႕ေလတြတ�မယ�။ အ(ဒက�� အ"ခဖ�န �

ထ(ထညပ��"ပ& install ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒလ�7ပ.ကညပ�။ သBငယ�1 င�တြတဆ&ပ���"ပ&ၾတြကပ။

ဒငရထတ(� software ျ႕ေလဆ��"ပ&။ (အဆ႕ေင+"ပတရ��႕ေ"ပပ။ ျ႕ေ"ပမ�သ�ပမယ�။)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 10: How to Write Android Application (2 to 12)

အမညပ�႕ေတြတ data ဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ျ ႕ေ႕ေတြတပတ(�အခ အခ1�/႕ေ�နရတြတမ� မ�မ�စခေ�တ. က�/က�႕ေ ဒ ဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒ ဒဒဒဒဒဒဒဒဒ ပငတယ�။ တစခေC င��"ပ&တစခေC င�$7@ တ(�အခ ပ��႕ေတြတမ� select ျ "ဖစခေ�႕ေနတ(�

button ျ႕ေတြတက�� click ရမယ- ���သ�ထပ။ (မပ�မယ��7;ခမ1�/မ�သ&သန �႕ေ�ရပပတယ�။)

Android Application ျ႕ေရနညပ� (၃)

Run on Emulator

အခ1�/�႕ေက"ပၾကမယ�။ Android application ျ ႕ေရနညပ�က��႕ေတလ�လခ1ငတယ�။ android device (ဖ�န �/tablet/note) ဒဒဒဒဒဒဒ ဒဒဒဒဒဒမ�မရ��တဘယ- ��လ�ပ+လ(။ မရ��လ("ဖစခေ တ

ယ�။ တြကနပ1<တတရ��ရမယ�။ ဒ ဒဒ အတ�လ�ပ+�ပ။အတ� (emulator) မ� run ၾကညပ�+ယ�႕ေလ။

သင�န �စခေ (၂) မ�လ�ပ�(Dတ(� project က�� real device မ� မ run ဘ( emulator မ� run ၾ ကညပ�႕ေ�အင�။ emulator တစခေ�လ�ပဘပ8ပ&ရင� run တ��င�သ��လ���ရပပ&။

ဒ&အတြတက� Android Virtual Device Manager က��သ��ၾကမယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 11: How to Write Android Application (2 to 12)

eclipse က��$ဖင��"ပ& tool bar ျ႕ေပၚက Android Virtual Device Manager ဆ�� တ(� tool က��ရ�ပ& click ပ။ ျ႕ေ အကပ��႕ေတြတ�မယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 12: How to Write Android Application (2 to 12)

အထကအတ��င�ဖညပ�$%က။ ( "ပသနရ��ရင� RAM 1024 က�� 512 or 256 or 128 ထၾကညပ�။)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 13: How to Write Android Application (2 to 12)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 14: How to Write Android Application (2 to 12)

HHl က��႕ေရြရပ& Start က�� click လ�ပ။

"ပ&ရင� ျ႕ေအက� ဖ�န �ပ��႕ေလ ျ႕ေတြတ�ရမယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 15: How to Write Android Application (2 to 12)

eclipse ဒ ဒဒဒဒဒဒဒဒ က��တြသပ&သင� န �စခေ (၂) မ�လ�ပ�(Dတ(� application က�� Run ပ။Hello world! ဆ��တ(� စခေတန �လက�� emulator မ�တြတ�ပလ�မ�+ယ�။

Android Application ျ႕ေရနညပ� (၄)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 16: How to Write Android Application (2 to 12)

ဒ&တစခေ�တရနညပ� (၂) မ� create လ�ပ�(Dတ(� Droid1 ရ(� coding ပ��င�က��နညပ�နညပ�ပင�ပမ ယ�။ အ(ဒ& application က�� run လ��က�င� Hello World! ဒဒလ��႕ေ�ပၚတယ+ဟ�တ- ။ဒ& ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒ ဒဒဒဒ တစခေ�တမ�မ�စခေ�တ. က�/က% သပၚလအင�လ�7ပ. ကမယ�။ Eclipse က��$ဖင�။

ဘယ�က; Eခမ�မ�ရ��တ(� Package Explorer ႕ေကန Droid1>src>com.example.droid1>DroidActivity.java က���$ဖင�။

package com.example.droid1;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.widget.TextView;//*****

public class DroidActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView tv = new TextView(this);//*****

tv.setText("Hello! I'm Dr. Htar Htar Lwin");//*****

setContentView(tv);//*****

}

@Overridehtarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 17: How to Write Android Application (2 to 12)

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

}

//***** ဒ ဒဒဒဒဒဒ ျ"ပထတ(� ျ႕ေနရတြတက��ထပ8 ပဘညပ�� /"ပငC7?င-?��က။ "ပ&ရင�႕ေတ phone န(� ခ1�တ�"ပ&တဘ( run မလ၊ Emulator န(� run မလ ၾက�/

က�န(� run ၾကညပ�။

Android Application ျ႕ေရနညပ� (၅)

Discussion

ဒ&သင�န �စခေတြတက�� tutorial ဒ ဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ႕ေသဘမ1�/ရခ(�တမ��� လက�႕ေတြတ�လ�ပ�႕ေဆင� မယ�7; ပ�� ဒဒဒ ဒဒဒဒဒဒဒဒ ဒ ဒဒဒဒ ဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒင�တြတက��ဥစခေပရခ(�ပတယ�။ ဒ&တစခေ� တ ျ႕ေ ရ��က သင� န �စခေတြတက��"ပန �"ပ&

ရ�င�လင�တြသမ�ဖစခေတယ�။ လက�႕ေတြတ�လ�ပHန �တြတစခေတင��ပဘ��� Android SDK က��အရင�႕ေဒင�လ�ပဆြပJ(ရမ�ဖစခေတယ�။

႕ေဒင�လ�ပဆြပJ("ပ&ရင� install ဒ ဒဒဒဒဒ လ�ပ�ပမယ�။ဘယ+� install လ�ပ+ယC ��တရြရပရပတယ�။ ႕ေကင�တ(�႕ေအလ�တစခေ��႕ေကတ D: drive ဒဒဒဒ ျ႕ေအက+�ထတဖစခေတယ�။ဥပမ D:\sdk ျ႕ေပ။

sdk မဟ�တ- ညပ�ၾက�/က�အမညပ�႕ေပလ���ရပတယ�။ D drive မရ��ရ7င-?ညပ�ၾက�/က�နရမ�ထငတယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 18: How to Write Android Application (2 to 12)

ပ��မ�ပထတ(�အတ��င� Start SDK Manager က�� check လ�ပဘပ8ပ& latest SDK tools

႕ေတြတန(� platform ျ ႕ေတြတက�� download ဒဒဒဒဒ ဒဒဒဒဒဒဒဆြဆ(ငတယ�။ က��ယ- �� ခ1င� တ(� platform ျ႕ေဘမ� check လ�ပ�"ပ& Install * packages က�� click လ�ပ���ပဘ(။

(* = number of packages)

Android 4.2 က�� download ဆြဆ(ထင�င�႕ေကင�ပတယ�။ (အင4နတဖြတ6င��"ပ&လ�ပ�မ�ပ။) ခ� မဆြဆ(႕ေသဘB ျ႕ေန7င-�?�မ�ဆြဆ(မယC ��လညပ� sdk folder (Android SDK က�� install လ�ပ�(Dတ(�႕ေနရ) ထ(က SDK Manager က��သ��ပ&ဆြဆ(လ���ရပတယ�။

႕ေနက4 စခေ��က eclipse က�� download ဆြဆ("ပ& unzip လ�ပဘပ�ပဘ���ပ။Eclipse ဒဒဒဒဒ မသ��ဘ( အ"ခ IDE ဒဒဒဒဒဒဒဒ ဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒသ��လညပ�ရပတယ�။ ဒပမယ�� ဒ&သင� န �စခေတြတ

မ� eclipse က��ဘ(အသ��ပ/တြသမ�ပ။Eclipse မ� android application ျ ႕ေ႕ေတြတရပဘင�ပဘ��� ADT Plugin က�� install လ�ပ�႕ေပရပဥမယ�။

ဒဒ ဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒတြတအလ��အသင��"ဖစခေ�င�႕ေတစခေတင-?�� �ရပပ&။Project တစခေ��က�� create လ�ပဘပ4(Dအခ eclipse က��အသ��ပ/သလ�� command line

tools ဒဒဒဒဒဒဒဒဒ က��လညပ�အသ��ပ/လ���ရပတယ�။ ဒ&မ�တ eclipse က��သအသ��ပ/တြသမ�ဖစခေတယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 19: How to Write Android Application (2 to 12)

က��ယ� create လ�ပဘပ8တ(� application က�� run ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒတ(�အခမ�လညပ� မ��ဘ��င�ဖ�န � ပၚမ� run :��င@လ�� emulator ျ ႕ေပၚမ�လညပ� run ဒဒဒဒဒ ဒဒဒ ဒ ဒဒ:��ငတယ�။နညပ�လမ�၂ခ�

လ��က��႕ေဖပ"ပ&သမ���ၾက�/က�နညပ�က��သ��ငတယ�။

Android Application ျ႕ေရနညပ� (၆)

( ဒက SDK 2.2 ဒဒဒဒဒဒဒ န(�လ�ပဘပ8တပ။က��7O� 3.0 န(�လ�ပဘပ4ဆ��ရင�"မင�တနညပ�နညပ�ဆြလ(႕ေန ဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒ ဒဒဒဒဒဒဒတလတြတရ��မယ�။ဒပမယ�7; ဆင�႕ေ"ပပမယ�။ )

ဒ&တစခေ�တ User Interface တစခေ��လ�7ပ.ကညပ�႕ေ�အင�(၁) Tool bar ျ႕ေပၚက create a new Android project ဆ��တ(� tool က�� click

လ�ပ။ ျ႕ေအကပ��အတ��င�ဖညပ��"ပ& Next က�� click လ�ပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 20: How to Write Android Application (2 to 12)

ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒ ဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒ&တစခေ�တက��ယ. က�/က� ပ��႕ေလတစခေ��႕ေ လက�႕ေရြရပလ��က ။ (႕ေမရြရခ1င-ညပ�ရပတယ�။) ျ"ပ&ရင� Next ပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 21: How to Write Android Application (2 to 12)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 22: How to Write Android Application (2 to 12)

အထက��မ�ပထသလ�� MyApp2>res>layout>activity_main.xml က��$ဖင��"ပ& ႕ေအက code ျ႕ေတြတ copy လ�ပ�"ပ&ထညပ�>-?��က။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 23: How to Write Android Application (2 to 12)

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

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"

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>

႕ေနက4 စခေ� MyApp2>values>strings.xml က��$ဖင��"ပ&အက code ျ ႕ေတြတထညပ�>-?��က။<?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>

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 24: How to Write Android Application (2 to 12)

Run ဒဒဒ ဒဒဒဒ ၾကညပ�။ဒ&တစခေ� emulator န(� run ထတ(�ပ��"ပပမယ�။ ျ႕ေအကပ��အတ�� င� Textbox တစခေ��န(� Button ဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒတစခေ��က��႕ေတြတ�ပလ�မ�+ယ�။ ဖ�န �န(�လညပ�ခ1�

တ�"ပ& run :��ငတယ�။ bin ျ ႕ေအက� apk ဖ��င��ပဘ�ယB"ပ&လညပ�ဖ�န �ထ(ထညပ��"ပ& install လ�ပ�ငတယ�။ (coding ပ��င�က�� ျ႕ေနက���(စခေ)မ�ရ�င�ပပမယ�။)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 25: How to Write Android Application (2 to 12)

Android Application ျ႕ေရနညပ� (၇)

သင�န �စခေ (၆) ရ(� coding ပ��င�က��အနညပ�ငယ��င�ပမ�ဖစခေတယ�။ ဒ&သင�န �စခေက textbox တစခေ��န(� button တစခေ��ထညပ�74ပ။ အရပဘငC��က��ယ8 ညပ�+ယ�� textbox န(� button အတြတက� layout က��"ပငC?င�ပမယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 26: How to Write Android Application (2 to 12)

For layout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

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"

screen မ�ရနပ��႕ေင@လက� width and height က��သတ+�တ- ��က4 ပ။ android:orientation="horizontal"

textbox န(� button က�� အလ1လ��က�႕ေနရခ1မယ- ���သတ+�တ4 ပ။

ဒက Textbox အတြတက။ <EditText android:id="@+id/edit_message"

android:layout_weight="1"

android:layout_width="0dp"

android:layout_height="wrap_content"

textbox မ�ရ��က8 ညပ�>-?���4(Dစခေရ��႕ေသလက;တ��င�အတဖစခေ�႕ေစခေမယ�� width and height

က��သတ+�တ4 ပ။ android:hint="@string/edit_message" />

ဒက button အတြတက။ <Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button_send" />

</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">My First App</string>

Application ရ(� name ပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 27: How to Write Android Application (2 to 12)

<string name="edit_message">Enter a message</string>

Application run လ��က�င� textbox အတြတင�မ�ပၚလမယ�� string “Enter a

message” ပ။ <string name="button_send">Send</string>

Application run လ��က�င� button မ�ပၚလမယ�� string “Send” ပ။ <string name="menu_settings">Settings</string>

<string name="title_activity_main">MainActivity</string>

</resources>

Android Application ျ႕ေရနညပ� (၈)

ဒ ဒဒဒဒဒဒဒဒ ဒ&တစခေ�တသင� န �စခေ (၆) မ� ျ"ပ/လ�ပ�(Dတ(� project က��ဆက�႕ေရတြသမ�ပ။ အ(ဒ&တ�န �က textbox တစခေ��န(� button က�� create လ�ပ�(D"ပ& ဒ&တစခေ�တ textbox ထ(

မ�စခေရ��က8 ညပ��"ပ& button ဒဒဒဒဒဒဒဒဒ က��ပ�င�အ(ဒ&စခေက�� display ဒ ဒဒဒလ�ပ�"ပဘ���အတြတက။သင� န �စခေ (၆) မ�ပ/လ�ပ�(Dတ(� MyApp က���"ပရြနပ6င��"ပ&အကအတ��င�ဆက- �ရြပQပ။

Open MyApp>res>layout>activity_main.xml

Add android:onClick="sendMessage" as follow:

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/button_send"

android:onClick="sendMessage" /> (ဒ&တစခေ-?��င�ဘ(ထပ8ပဘညပ�။)Open MyApp>src>MainActivity.java

Add these codes.

package com.example.myfirstapp;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 28: How to Write Android Application (2 to 12)

import android.widget.EditText;

public class MainActivity extends Activity {

public final static String EXTRA_MESSAGE =

"com.example.myfirstapp.MESSAGE";

/** Called when the user clicks the Send button */

public void sendMessage(View view) {

Intent intent = new Intent(this,

DisplayMessageActivity.class);

EditText editText = (EditText)

findViewById(R.id.edit_message);

String message = editText.getText().toString();

intent.putExtra(EXTRA_MESSAGE, message);

startActivity(intent);

}

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.activity_main, menu);

return true;

}

}

Tip: In Eclipse, press Ctrl + Shift + O to import missing classes

Now you need to create the DisplayMessageActivity class in order

for this to work.

To create DisplayMessageActivity class

1. Click New in the toolbar.

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 29: How to Write Android Application (2 to 12)

2. In the window that appears, open the Android folder and

select Android Activity. Click Next.

3. Select BlankActivity and click Next.

4. Fill in the activity details:

o Project: MyFirstApp

o Activity Name: DisplayMessageActivity

o Layout Name: activity_display_message

o Navigation Type: None

o Hierarchial Parent:

com.example.myfirstapp.MainActivity

o Title: My Message

Click Finish.

Figure 1. The new activity wizard in Eclipse.

Open the DisplayMessageActivity.java file.

The class already includes an implementation of the required

onCreate() method.

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 should look like this:

public class DisplayMessageActivity extends Activity {htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 30: How to Write Android Application (2 to 12)

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_display_message);

}

}

All subclasses of Activity must implement the onCreate() method.

The system calls this when creating a new instance of the activity.

It is where you must define the activity layout and where you should

perform initial setup for the activity components.

Add it to the manifest

You must declare all activities in your manifest file,

AndroidManifest.xml, using an <activity> element.

You used the Eclipse tools to create the activity, it creates a default

entry.

It should look like this:

<application ... >

...

<activity

android:name=".DisplayMessageActivity"

android:label="@string/title_activity_display_message" >

<meta-data

android:name="android.support.PARENT_ACTIVITY"

android:value="com.example.myfirstapp.MainActivity" />

</activity>

</application>

Receive the Intent

Every Activity is invoked by an Intent, regardless of how the user

navigated there.

You can get the Intent that started your activity by calling

getIntent() and retrieve the data contained within it.

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 31: How to Write Android Application (2 to 12)

In the DisplayMessageActivity class’s onCreate() method, get the

intent and extract the message delivered by MainActivity:

Intent intent = getIntent();

String message =

intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

Display the Message

To show the message on the screen, create a TextView widget and

set the text using setText().

Then add the TextView as the root view of the activity’s layout by

passing it to setContentView().

The complete onCreate() method for DisplayMessageActivity now

looks like this:

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// Get the message from the intent

Intent intent = getIntent();

String message =

intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view

TextView textView = new TextView(this);

textView.setTextSize(40);

textView.setText(message);

// Set the text view as the activity layout

setContentView(textView);

}

Finally, DisplayMessageActivity class looks like this:

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 32: How to Write Android Application (2 to 12)

package com.example.myfirstapp;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

// Get the message from the intent

Intent intent = getIntent();

String message =

intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

// Create the text view

TextView textView = new TextView(this);

textView.setTextSize(40);

textView.setText(message);

// Set the text view as the activity layout

setContentView(textView);

}

}

You can now run the app.

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 33: How to Write Android Application (2 to 12)

When it opens, type a message in the text field, click Send, and the

message appears on the second activity.

Figure 2. Both activities in the final app, running on Android 4.0.

Android Application (9) က�� htarhtarlwin.blogspot.com မ�ၾကညပ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 34: How to Write Android Application (2 to 12)

Android Application ျ႕ေရနညပ� (၁၀)

ဒ&တခတတြလယလြယ- ယ�႕ေလတစခေ��လ�7ပ.ကညပ�႕ေ�အင�။Android device ျ ႕ေပၚမ� current time က�� display လ�ပ�"ပမယ�� application တစခေ��႕ေရမယ�။

အရပဘငC�� project တစခေ�� create လ�7ပ-?��က။Project name က�� skeleton လ��႕ေ�ပပ& activity name က�� Now လ��႕ေ�ပပ။

"ပ&ရင� Now.java file မ�အက source code ျ႕ေတြတက��ရ��က8 ညပ�။

package com.example.skeleton;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import java.util.Date;

public class Now extends Activity implements View.OnClickListener

{

Button btn;

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

btn = new Button(this);

btn.setOnClickListener(this);

updateTime();

setContentView(btn);

}

public void onClick(View view) {

updateTime();

}

private void updateTime() {

btn.setText(new Date().toString());

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 35: How to Write Android Application (2 to 12)

}

}

Discussion

package com.example.skeleton;

ဒ႕ေကတ package က�� declare လ�ပဘပ4ပ။

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import java.util.Date;

ဒဒဒဒဒဒ ဒ႕ေကတက��ယ�� program မ�သ��မယ�� class ျ႕ေတြတက�� import လ�ပဘပ4ပ။ android-

specific class အမ1စခေ�က android package ထ(မ�ရ��ပတယ�။

public class Now extends Activity implements

View.OnClickListener {

Button btn;

Activity Now ဟ public class ျ "ဖစခေ�"ပ& android.app.Activity ဆ��တ(� base

class ႕ေကန extend လ�ပဘပ8တပ။ ဒ& program မ�ဆ��ရင� Now ဟ button (btn) တစခေ��က�� hold လ�ပဘပ8ပတယ�။

(Button ဆ��တ android widget တစခေ��ပ။ widget ဆ��တ application မ� သ��တ(� UI element ျ ႕ေတြတက��႕ေ"ပတပ။ Widget ျ ႕ေတြတအလ��ဟ View ဆ��တ(� base

class ႕ေကန extend လ�ပတယ�။) Button click ဒဒ ျ႕ေတြတအလ��က��ဒ& activity ထ(မ�ဘ( trap လ�ပ�1ပဘင4ၾကင�� Now ဟ

OnClickListener က�� လညပ� implement လ�ပဘပ8ပတယ�။

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

btn = new Button(this);

btn.setOnClickListener(this);

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 36: How to Write Android Application (2 to 12)

updateTime();

setContentView(btn);

}

Activity က�� စခေ"ပ&ဆ��တန(� onCreate() ဆ��တ(� method က�� invoke လ�ပတယ�။The first thing you should do is chain upward to the superclass, so

the stock Android activity initialization can be done.

"ပ&ရင� button instance တစခေ��က�� create လ�ပတယ�။ ျ"ပ&တ button click ျ႕ေ တြတအလ��က�� instance ဆ&ပ���ဘ��� setOnclickListener() က��သ��ပတယ��။

အလ��ပ&ရင� updateTime() method ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒက�� ျ႕ေ ခၚပတယ�။ ဒ&႕ေနရမ�ခၚတ႕ေက တ program က�� run ဒဒ လ��က4 န(�ဘ button မ�မပ�င� current time က�� display လ�

ပ�"႕ေပအင။ ျ"ပ&တ setContentView() ျ႕ေပ။

public void onClick(View view) {

updateTime();

}

Button တစခေ��က�� click လ��က�င� အ(ဒ& button အတြတက� configure လ�ပဘပ8တ(� onClickListener instance မ� onClick() method က�� invoke လ�ပတယ�။

အ(ဒ&အခ updateTime method က�� call ဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒ ျ ႕ေတတပ။ ဒ&တစခေ� ခၚတ႕ေက တ button က�� click လ�႕ေပ+�ခၚမ�ပ။

private void updateTime() {

btn.setText(new Date().toString());

}

Activity open ဒဒဒဒဒဒဒဒဒ လ�7ပ-?��က4 န(�သ���မဟ�တ� button က�� click လ�7ပ-?��က4 န(� button

ရ(� label မ� current time ဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒ ဒဒဒဒက��႕ေတြတ�ရမ�ပ။အ(လ��႕ေတြတ�႕ေရအ7င-?�� �

setText() က��သ��ထပတယ�။ "ပ&ရင�႕ေတ program run ဒဒဒဒ ဒဒဒဒၾကညပ�။ ျ႕ေအက� ပ��အတ��င�တြတ�ပမယ�။တြလတ4 (D႕ေ နရလက�� tap လ��က။ current time က တစခေ� tap ဒဒတ��င� တစခေ�ပင�တြသပမယ�။ဘ

လ���ဆ�� အခ1�န �႕ေတြတကအ"မ(႕ေ"ပင�နတက��။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 37: How to Write Android Application (2 to 12)

ဒ&တစခေ� onCreate() method ထ(က updateTime() က��"ဖ/တ�"ပ& run ၾကညပ� လ။ run run ခ1င� current time က��႕ေတြတ�မ�မဟ�တ� S။ tap လ��က+� current

time ဒဒဒဒဒ ဒ ဒဒဒဒဒဒ ျ႕ေပၚလလ�မ�+ယ�။စခေမ�ၾကညပ� ။

Android Application ျ႕ေရနညပ� (၁၁)

Widget ျ႕ေတြတက�� create လ�ပ�"ပ& activity မ� attach လ�ပဘပ4က�� Java code ျ႕ေရပ& လ�7ပ-?���ရသလ��ဘ( ("ပ&ခ(�တ(�အခန �မ�လ�ပ�(Dသလ��႕ေပ) XML-based layout file ျ ႕ေ

ဒဒဒဒဒဒဒ ဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒ တြတက��အသ��ပ/"ပ&လ�7ပ-?���လညပ�ရပတယ�။ဒ&နညပ�ကပ��အသ��မ1ပတယ�။ XML-based

layout ဆ��တက widget အခ1င�ခ1င�ရ(� relationship န(� widget န(� သBတ���ရ(�

continer ျ ႕ေတြတဘယ- �� relationship ရ��တယC ��တက��႕ေဖ႕ေပပတပ။ XML-based

layout ျ ႕ေတြတက�� resource ျ ႕ေတြတအ"ဖစခေ@?တ+�တ4 မ��� layout file ျ ႕ေတြတက�� res

folder ျ႕ေအက+�ထပတယ�။XML element ျ႕ေတြတရ(� attribute ဒ ဒ ဒဒဒ ဒဒဒ ဆ��တကတကယ�႕ေတ properties ျ႕ေတြတပ။ widget ျ႕ေတြတဟ ဘယ- ��ပ��စခေ�မ1�/ဖစခေ�မယ�၊ container ျ႕ေတြတကဘယ- �� ျ"ပ/မBသင�74?ယC��

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 38: How to Write Android Application (2 to 12)

တ(� properties ဒဒဒဒ ျ႕ေ႕ေတြတပ။ဥပမ Button element တစခေ��ရ(� attribute value က

android:textStyle = “bold” ဒဒဒဒဒဒဒဒဒ ဆ��ပတ။ဆ��လ��တက button မ�ပၚမယ�� text က

bold ျ"ဖစခေ�မယ- ���ဆ��လ��တပ။ ဒ& layout ျ ႕ေတြတန(�ပတ@က�"ပ& aapt tool ႕ေကနပTပ& R.java ဆ��တ(� file က��

generate လ�ပ�႕ေပပတယ�။ layout ျ ႕ေတြတန(� layout ထ(က widget ျ ႕ေတြတက�� သ��မယC ��ရင� R.layout.main or R.id.button အစခေရ��သ"ဖင��႕ေခၚသ��ငတယ�။

က( အခ�တစခေ� xml code က��သ��ပ& button ဒ ဒ ဒဒဒဒဒဒတစခေ��လ�7ပ.ကညပ�႕ေ�အင�။အရပဘငC��

project တစခေ�� create ဒ ဒဒဒ ဒဒဒဒဒဒဒ လ�ပ။အမညကေV��႕ေ တ NowRedux လ��႕ေ�ပပ။ layout

name က��႕ေတ main လ��႕ေ�ပလ��က။ ျ႕ေ အက xml code ျ ႕ေတြတက�� ကBပ& res/layout ျ႕ေအက� main.xml file မ�ကBထညပ�>-�?�က။ ျ"ပ&��ရင� run ၾကညပ�>-?��က�။ button ဒဒဒဒ တစခေ��႕ေပၚလမယ�။အ(ဒ& button က�� tap လ�7ပ.ကညပ��။ ဘမ�"ဖစခေ-မ�မဟ�တ�

ဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဘB။ဘမ�မမလ�႕ေပ� သတက��။ button ဒဒဒဒ ဒ တစခေ��႕ေပၚလဘ���သက@က� (လ�ပဘပ8သတလ။<RelativeLayout

xmlns:androi

d="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools">

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="" />

</RelativeLayout>

ဒ႕ေကတ XML layout file မ� button တစခေ��က�� create လ�ပဘပ8တပ။

xmlns:android="http://schemas.android.com/apk/res/

android"

Root element မ� Android XML namespace က��ဒ&လ�� declare ဒဒလ�ပ�ပမယ�။အ" ခ element ျ ႕ေတြတ႕ေကတ root ရ(� children ျ ႕ေတြတ"ဖစခေ�"ပ& name space

declaration က�� inherit လ�ပတယ�။

android:id="@+id/button"

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 39: How to Write Android Application (2 to 12)

ဒ& button က�� jave code ဒဒဒဒဒဒ ႕ေကနလ�မ�ယBသ��မ�ဆ��႕ေတသB�က�� identifier တစခေ��႕ေ ပထရမယ�။ android:id attribute က��သ��ပ&တပ။ element တ��င�က�� id ျ႕ေပစခေရမ

လ��ပဘB။ java code ႕ေကနလ�မ�ခၚသ��မယ�� element ျ ႕ေတြတက��သ id ျ ႕ေပဘ���လ��ပတယ�။

Button

Button ဆ��တက XML element ရ(�အမညပ�႕ေပ။ Button ဆ��တ Android-

supplied widget တစခေ��"ဖစခေ�႕ေ႕ေလတ class name ဒ ဒက��ဘ(ယBသ��လ��က4 ပ။တက ယ- ���သ က��ယ��H� widget တစခေ��က�� android.view.View ရ(� subclass အ"ဖစခေW(�

create လ�ပ+ယC ��ရင�႕ေတ full package declaration လ�ပ�မယ�။ ဥပမ com.example.MyWidget လ��႕ေ�ရရမ�ပ။

android:layout_width="wrap_content"

android:layout_height="wrap_content"

ဒ႕ေကတ button ရ(� width န(� height က��သတ+�တ4 ပ။

android:text=""

button မ�ပ႕ေၚစခေခ1င4(D text ဒဒဒဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒ ပ။ဒ&မ�တဘမ�႕ေမပ႕ေၚစခေခ1င-?�� � space ဘ(ထတယ�။

အခ�ဆ��ရင� button တစခေ��က�� XML code န(႕ေ�ရထတ(�ဖ��င�"ဖစခေ4(D main.xml ဖ��ငX res/layout ဒဒ မ�ရ��႕ေနပပ&။ဒ& layout file က�� java code ႕ေကန access လ�ပ�င�

ဘ���ဆ��ရင� NowRedux.java file ထ(က onCreate() call back ထ(မ� setContentView(R.layout.main);

ဆ��တ(� statement တစခေ��ထညပ�>-?��က���ပဘ(။ "ပ&တ button က�� သ��ဘ���ဆ��ရင�႕ေတ

findViewById();

ဆ��"ပ&ခၚသ��ရ��ပဘ(။ ႕ေအက java code ျ႕ေတြတက�� NowRedux.java ဖ��ပဘင8(ကBထညပ�>-�?�က။

package com.example.layouts;

import android.app.Activity;

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 40: How to Write Android Application (2 to 12)

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import java.util.Date;

public class NowRedux extends Activity

implements View.OnClickListener {

Button btn;

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

btn=(Button)findViewById(R.id.button);

btn.setOnClickListener(this);

updateTime();

}

public void onClick(View view) {

updateTime();

}

private void updateTime() {

btn.setText(new Date().toString());

}

}

"ပ&ရင� run ဒဒဒ ဒဒဒဒဒဒဒဒ ၾကညပ�>-?��က�႕ေပ။ ျ႕ေအက� ပ��မ1�/တြတ�ရမယ�။ဒ&တစခေ� တ button

က�� tap ဒ ဒဒဒ လ��က4 ��င�အခ1�န �႕ေ"ပင�တြသတတြတ�မယ�။အရင� program န(�အတBတBပ ဘ(။ ဒ&တစခေ��႕ေကတ button က�� XML code န(႕ေ�ရလ��က4 ပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 41: How to Write Android Application (2 to 12)

Android Application ျ႕ေရနညပ� (၁၂)

Employing Basic Widget

ဒ&တစခေ� widget ျ ႕ေတြတက��ဘယ- ��အသ��ခ1မလ(ၾကညပ�႕ေ�အင�။ Widget ဆ��တ filed,

label, button အစခေရ��တ႕ေတြတပ။Assigning Labels

Label က�� android မ�တ TextView လ��႕ေ�ခၚတယ�။ user က edit လ�7ပ-�?��မရ ဒဒဒဒဒဒဒဒဒဒဒဒ ဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒ ဒဒဒ ဒဒဒဒ ဘB။သBတ���က��ဘအတြတက@ �� လ(ဆ��႕ေတဥပမ textbox တစခေ��ထ(မ� အမညကေV��ရ��

က8ညပ��႕ေစခေခ1င4?ယC��ပတ။ user ႕ေအနန(� ဒ& box ဒဒထ(မ�ဘထညပ��မယC ��တသ�႕ေအင�ညပ န �"႕ေပပတပ။ label က�� အ(ဒ& textbox န(�ကပ-1 ကမက+�ထညပ��႕ေပမ�အဆင�႕ေ"ပမယ�႕ေ

လ။Label တစခေ��က�� create လ�ပ�1င�င� TextView instance က�� create လ�ပ�မယ�။ ျ႕ေန

က4 စခေWညပ�က XML layout file ထ(မ� TextView element တစခေ��ထပ�"ပ&လညပ� htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 42: How to Write Android Application (2 to 12)

create ဒဒ ဒဒဒ လ�ပ�ပဘင4ယ�။႕ေအပၚက button က��လ�ပ�(Dသလ��မ1�/ပ။ android: text property

ဒဒဒဒဒဒ ဒဒဒဒဒဒဒဒဒဒဒ မ�တက��ယ�႕ေပ႕ေၚစခေခ1င4(D text ဒဒဒဒဒဒဒဒဒဒဒဒ က��ထညပ��႕ေပ။သB�မ�ရ��တ(� properties ျ႕ေတြတက��ၾကညပ�႕ေ�အင�။android:typeface

monospace လဘလပ။android:textstyle

bold, italic or bold and italic လပ။android:textColor

ဘရင�႕ေလန(႕ေ�ပၚခ1င4လ(႕ေပ။ RGB hex format ဒဒဒဒန(႕ေ�ရရတယ�။ဥပမ -အန&႕ေရ င�"ဖစခေ�1င�င� #FF0000 ျ႕ေပ။

နမBနတစခေ��လ�7ပ.ကညပ�႕ေ�အင�။ project တစခေ�� create လ�ပ�"ပ& Label လ���အမညပ�႕ေ ပပ။ activity name က�� main လ��႕ေ�ပပ။ ျ"ပ&ရင� main.xml file မ�အက code

႕ေတြတကBထညပ��"ပ& run ပ။ <TextView

xmlns:android="http://schemas.android.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" />

ဒ႕ေကတ output ျ႕ေပ။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 43: How to Write Android Application (2 to 12)

Fields of Green. Or Other Colors.

ဒ&တစခေ� Edit Text ႕ေအၾကင�ပပမယ�။Edit Text widget ဆ��တ TextView ရ(� subclass ပ။ Edit Text ရ(�

properties ျ႕ေတြတ႕ေကတandroid:autoText

auto spelling ရခ1င�ပဘင@��ရပတယ�။

android:capitalize

ရ��က8 ညပ�>-?���4(D ပထမဆ��စခေလ��က�� capital အ"ဖစခေ� auto ျ႕ေ"ပင�ပစခေဘ���ပ။

android:digits

digit ျ႕ေတြတက��သ လက��ခ1င�င�႕ေပ။

android:singleline

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 44: How to Write Android Application (2 to 12)

single line or multiline လသတ+�တ� ���ပ။

android:numeric

numeric-only input အတြတက။

android:password

password input အတြတက။

android:phoneNumber

phone number ျ႕ေတြတဘ(ရ��က8 ညပ�7�?���။

Field ဆ��တ(� project တစခေ�� create လ�ပ။ activity name က�� FieldDemo

လ��႕ေ�ပပ။main.xml မ� ျ႕ေအက code ျ႕ေတြတကBထညပ�။<?xml version="1.0" encoding="utf-8"?>

<EditText

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/field"

android:layout width="fill parent"

android:layout height="fill parent"

android:singleLine="false"

/>

android:singleLine ဟ false ဒ ဒဒဒဒဒဒဒဒဒဒ ျ "ဖစခေ4(Dအတြတက� စခေရ��က8 ညပ�74(Dအခတစခေ-�?� င�မက

ရ��က8 ညပ��ငတယ�။ FieldDemo.java file မ�အက code ျ႕ေတြတကBတြတကBထညပ�။package com.commonsware.android.basic;

import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

public class FieldDemo extends Activity {

@Override

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 45: How to Write Android Application (2 to 12)

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

EditText fld=(EditText)findViewById(R.id.field);

fld.setText("Licensed under the Apache License, Version 2.0 " +

"(the \"License\"); you may not use this file " +

"except in compliance with the License. You may " +

"obtain a copy of the License at " +

"http://www.apache.org/licenses/LICENSE-2.0");

}

}

Run ၾကညပ�။ ျ႕ေအကပ��က��႕ေတြတ�ပမယ�။

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin

Page 46: How to Write Android Application (2 to 12)

သင�န �စခေ (၁၃)

htarhtarlwin.blogspot.comwww.facebook.com/htarhtarlwintunwww.facebook.com/groups/htarhtarlwin