Android Appliction PDF
Android Appliction PDF
Chapter 1
Getting Started
1.1. JDK Installation 1
Chapter 2
2.4. Tabs 66
Chapter 3
BASIC Language
3.1. Variable and Object 70
i
3.3. Expression 88
Chapter 4
ii
4.7. Activity_Pause 163
Chapter 5
Module
5.1. Activity Module 178
Chapter 6
Chapter 7
Designer
7.1. Menu 195
iii
7.5. Layout Variant 257
Chapter 8
Tutorials
8.1. Maths Trainer 302
Chapter 9
iv
9.9. "Process has timeout" Message 360
v
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 1
Getting Started
Basic4Android
တုိ႕ျဖစ္ပါတယ္၉
i586.exe file ကို run ပါ၉ Winodws 64-bit OS ဆိုရင္ jdk-7u45-windows-x64.exe ကို run ျပီး
ပံု ဿ-ဿ
1
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၀
ပံု ဿ-၁
2
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၂
ပံု ဿ-၃
3
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၄
sdk.rar ကုိ D drive ေအာက္မွာ ျဖည္ခ်လိုက္ရင္ ရပါျပီ၉ (D drive မရွိလဲ အျခား drive တစ္ခု
ခုမွာ ျဖည္ခ်ႏုိင္ပါတယ္)
4
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၅
ပံု ဿ-၆
5
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၇
ပံု ဿ-ဿှ
6
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-ဿဿ
Uncheck လုပ္ပါ
ပံု ဿ-ဿ၀
7
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
1.3.1. B4A Registration
copy ကူးထည့္ျပီးမွ run ပါ၉ hhl@gmail.com လုိ႕ ရိုက္ထည့္ျပီး „Generate license file‟ button ကုိ
ပံု ဿ-ဿ၁
Register ျပဳလုပ္ျပီးေၾကာင္း dialog box ေပၚလာရင္ „Ok‟ button ကို ႏွိပ္ပါ၉ (ပံု ဿ-ဿ၂)
ပံု ဿ-ဿ၂
Basic4android ေအာက္မွာ ထားပါ၉ Desktop ေပၚက icon ကို double click လုပ္ျပီး
8
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
run ပါ၉ (ပံု ဿ-ဿ၃) မွာ ျပထားတဲ့အတုိင္း Integrated Development Environment (IDE) window
ျဖစ္ပါတယ္၉
ပံု ဿ-ဿ၃
javac.exe, android.jar file ေတြနဲ႕ Additional Libraries folder ရွိရာ path ေတြကို B4A
မွာ configure လုပ္ရမယ္၉ IDE window ရဲ႕ menu bar မွာ [Tools > Configure Paths] ကို ေရြးပါ၉
(ပံု ဿ-ဿ၄)
9
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-ဿ၄
ပံု ဿ-ဿ၅
10
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-ဿ၆
ပံု ဿ-ဿ၇
11
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၀ှ
ပံု ဿ-၀ဿ
12
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၀၀
ပံု ဿ-၀၁
(ပံု ဿ-၀၁) အတုိင္း ေပၚလာရင္ „Ok‟ button ကို ႏွိပ္လိုက္ပါ၉ အခုဆိုရင္ application ေရးရန္
အသင့္ျဖစ္ပါျပီ၉
13
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
1.4. Creating Android Virtual Device (AVD) or Emulator
Emulator ဆိုတာ PC ေပၚမွာ real device ကို simulate လုပ္ေပးတဲ့ software တစ္ခု
ျဖစ္ပါတယ္၉ Application ေရးျပီးရင္ real device (phone/tablet) နဲ႕ ခ်ိတ္ျပီး install လို႕ရသလို
Emulator မွာလည္း install လုပ္လို႕ရပါတယ္၉ Emulator ကေတာ့ real device ထက္ ေႏွးေကြး
IDE window ရဲ႕ menu bar မွာ [Toos > Run AVD Manager] ကို ေရြးပါ၉ (ပံု ဿ-၀၂)
ပံု ဿ-၀၂
14
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Android SDK Manager window မွာ [Tools > Manage AVDs…] ကို ေရြးပါ၉ (ပံု ဿ-၀၃)
ပံု ဿ-၀၃
ပံု ဿ-၀၄
15
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(ပံု ဿ-၀၅) အတုိင္း ေရြးခ်ယျ္ပီး „Ok‟ button ကုိ ႏွိပ္ပါ၉
ပံု ဿ-၀၅
16
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အခုဆိုရင္ emulator တစ္ခုကို create လုပ္လုိ႕ ျပီးပါျပီ၉ (ပံု ဿ-၀၆)
ပံု ဿ-၀၆
Emulator ကို ဖြင့္ခ်င္ရင္ Emulator1 ကို select လုပ္ျပီး „Start‟ button ကုိ ႏွိပ္ပါ၉ (ပံု ဿ-၀၇)
ပံု ဿ-၀၇
17
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၁ှ
ပံု ဿ-၁ဿ
18
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၁၂
(ပံု ဿ-၁၂) အတုိင္း ျမင္ရရင္ application ကို emulator မွာ install လုပ္ဘို႕ အသင့္ျဖစ္ပါျပီ၉
19
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
o Device မွာ Settings ကေန Unknown sources နဲ႕ USB debugging ကုိ
ပံု ဿ-၁၃
ပံု ဿ-၁၄
ျဖစ္ပါတယ္၉
20
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
21
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၂ှ
ပံု ဿ-၁၇
Plus1.4 ကို device မွာ install လုပ္ျပီး open လုပ္ပါ၉ (ပံု ဿ-၂ဿ) မွာကဲ့သုိ႕ ျမင္ရမယ္၉ Start button
ကုိ ႏွိပ္ပါ၉
22
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ B4A IDE menu မွာ (ပံု ဿ-၂၁) ပါ အဆင့္အတိုင္း လုပ္ပါ၉ [B4A Bridge > Connect
ပံု ဿ-၂၁
23
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Devcie မွာျပထားတဲ့ IP address ကို ရိုက္ထည့္ျပီး Ok ကုိ ႏွိပ္ပါ၉ ပံု (ဿ-၂၂)
ပံု ဿ-၂၂
မွာလည္း (ပံု ဿ-၂၀) မွာ ျပထားတဲ့အတုိင္း Connected ျဖစ္သြားရင္ program run ရန္ အသင့္ျဖစ္ပါ
ျပီ၉
ပံု ဿ-၂၃
Desktop ေပၚက icon ကုိ double click လုပ္ျပီး run ပါ၉ (ပံု ဿ-၂၄) အတုိင္း IDE
window ေပၚလာမယ္၉
Code Area
Tab Area
ပံု ဿ-၂၄
24
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Save the Program
Project file ကုိ save လုပ္ရန္ [File > Save] ကို ေရြးပါ၉ (ပံု ဿ-၂၅)
ပံု ဿ-၂၅
Project တစ္ခုအတြက္ folder တစ္ခု လုပ္ရမယ္၉ ဒါေၾကာင့္ New folder ကုိ ေရြးပါ၉
(ပံု ဿ-၂၆)
ပံု ဿ-၂၆
25
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Folder name ကုိ „FirstProgram‟ လို႕ေပးျပီး „Open‟ button ကို ႏွိပ္ပါ၉ (ပံု ဿ-၂၇)
ပံု ဿ-၂၇
File name မွာ MyFirst လို႕ ေပးပါ၉ MyFirst ဟာ project file name ျဖစ္ပါတယ္၉ File type
ကေတာ့ „.b4a‟ ျဖစ္ပါတယ္၉ ျပီးရင္ „Save‟ button ကုိ ႏွိပ္ပါ၉ (ပံု ဿ-၃ှ)
ပံု ဿ-၃ှ
26
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အခုဆိုရင္ D:\FirstProgram folder ထဲမွာ MyFirst.b4a ဆိုတဲ့ project file တစ္ခု create
လုပ္ျပီးသြားပါျပီ၉
Icon
Icon ဆိုတာ ကိုယ့္ application ကုိ device မွာ install လုပ္ျပီးတဲ့အခါ device screen မွာ
(ပံု ဿ-၃ဿ) ကိုၾကည္ပါ၉ CB Bank application ရဲ႕ icon ကုိ screen မွာျမင္ရပံုျဖစ္ပါတယ္၉
ပံု ဿ-၃ဿ
Application အတြက္ စိတ္ၾကိဳက္ icon တစ္ခု ျပဳလုပ္ထားပါ၉ ျပီးရင္ IDE menu bar မွာ
[Project > Choose Icon] ကို ေရြးျပီး icon ကုိ ေရြးေပးလိုက္ပါ၉ Icon မေရြးေပးရင္ေတာ့ Android
Package name
Application အတြက္ package name ေပးရပါမယ္၉ IDE menu bar မွာ [Project >
Package name] ကို ေရြးပါ၉ (ပံု ဿ-၃၀) မွာ ျပထားသလို package name ေပးလုိက္ျပီး „Ok‟ button
ကုိ ႏွိပ္ပါ၉
ပံု ဿ-၃၀
27
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Coding
Program code ကုိ စေရးပါမယ္၉ Code area မွာ ေအာက္ပါအတုိင္း နည္းနည္း ျပင္ေရးလိုက္
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
End Region
#FullScreen: False
#IncludeTitle: True
End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
28
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For
example:
End Sub
Sub Activity_Resume
End Sub
End Sub
Application ကုိ run ရန္ device ကို PC နဲ႕ ခ်ိတ္ပါ၉ (Emulator မွာ install လုပ္ခ်င္ရင္ေတာ့
emulator ကုိ အရင္ဖြင့္ထားပါ) IDE tool bar ေပၚက Compile options dropdown list မွာ
ပံု ဿ-၃၁
ျပီးရင္ IDE tool bar ေပၚက icon ကို click ပါ၉ (ပံု ဿ-၃၂) မွာကဲ့သုိ႕ dialog box ကုိ
ျမင္ရပါမယ္၉
29
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၃၂
IDE window ရဲ႕ Tabs area မွာ „Logs‟ tab ကို ေရြးလုိက္ပါ၉ (ပံု ဿ-၃၃)
ျမင္ရတာပါ၉
ပံု ဿ-၃၃
30
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ဿ-၃၄
အခုဆိုရင္ Application ကုိ device မွာ install လုပ္ျပီး ျဖစ္ပါတယ္၉ APK file ကုိလည္း
ပံု ဿ-၃၅
31
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
1.7. Second Program
First Program မွာ User Interface (UI) မပါပါဘူး၉ Second Program မွာေတာ့ UI သံုးျပီး
ရိုးရွင္းတဲ့ application တစ္ခု ေရးျပပါမယ္၉ UI မွာ button တစ္ခု ထည့္ထားပါမယ္၉ Button ကုိ
IDE widow ရဲ႕ menu bar မွာ Designer ကုိ ေရြးပါ၉ Designer နဲ႕ Abstract Designer
ပံု ဿ-၃၆
User interface layout ကုိ Abstract Designer မွာသာမက emulator နဲ႕ real device
Abstract Designer မွာ ျမင္ရတဲ့ view ေတြဟာ application ကုိ run လုိက္ရင္ ျမင္ရမယ့္အတုိင္း
အတိအက် မျဖစ္ပါဘူး၉
လုပ္ခ်င္ရင္ device ကုိ PC နဲ႕ ခ်ိတ္ထားရမယ္၉ Emulator မွာ design လုပ္ခ်င္ရင္ emulator ကုိ
ဖြင့္ထားရမယ္၉
32
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ device/emulator နဲ႕ IDE ကုိ ခ်ိတ္ဆက္ေပးရပါမယ္၉ ခ်ိတ္ဆက္ နည္းကေတာ့
Designer window မွာ [Tools > Connect to Device/Emulator >] ကို ေရြးပါ၉ သိ႕ု မဟုတ္
Designer window မွာ (ပံု ဿ-၃၇) မွာ ျပထားတဲ့အတုိင္း chain ပံုေလးကို double click လုပ္လုိက္ပါ၉
ပံု ဿ-၃၇
PC မွာ device ေရာ emulator ပါ ခ်ိတ္ထားရင္ေတာ့ (ပံု ဿ-၄ှ) အတိုင္း dialog box
ပံု ဿ-၄ှ
ပံု ဿ-၄ဿ
33
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Designer window ရဲ႕ menu bar မွာ [Add View > Button] ကုိ ေရြးပါ၉ (ပံု ဿ-၄၀)
Abstract Designer မွာ (ပံု ဿ-၄၁) မွာကဲ့သို႕ „Button‟ view တစ္ခု ေရာက္လာပါမယ္၉
Device နဲ႕ ခ်ိတ္ဆက္ထားရင္ေတာ့ (ပံု ဿ-၄၂) မွာ ျပထားတဲ့အတုိင္း ျမင္ရပါမယ္၉ Emulator နဲ႕
34
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Designer window မွာ
Text: Click Me
ပံု ဿ-၄၄
Designer window menu bar မွာ [Tools > Generate Members] ကို ေရြးပါ၉ (ပံု ဿ-၄၅)
မွာ ျပထားတဲ့အတုိင္း Click ကုိ check လုပ္ပါ၉ Generate members > Close button ေတြကို ႏွိပ္ပါ၉
ပံု ဿ-၄၅
35
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ Designer window ရဲ႕ menu မွာ [File > Save As] ကို ေရြးပါ၉ (ပံု ဿ-၄၆) ကဲ့သို႕
ပံု ဿ-၄၆
IDE code area မွာ Activity_Create နဲ႕ btnCM_Click sub ေတြကို ေအာက္ပါအတုိင္း
Activity.LoadLayout("Layout1")
End Sub
Sub btnCM_Click
Msgbox("Second Program”,"Welcome!")
End Sub
ျပီးရင္ program ကို run ပါ၉ (ပံု ဿ-၄၇) အတုိင္း ျမင္ရမယ္၉ „Click Me‟ button ကုိ ႏွိပ္ပါ၉
36
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
37
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 2
IDE မွာ (ပံု ၀-ဿ) တြင္ျပထားတဲ့အတုိင္း အပိုင္း ၂ပိုင္း ရွိပါတယ္၉ ပံု ၀-ဿ
Code Area
Detail Area
Tabs Area
38
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.1. Menu and Toolbar
New
Open Source
Save
Export As Zip
Page Setup
Print Preview
Exit
39
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.1.2. Edit Menu
Cut (Ctrl+X)
Copy (Ctrl+C)
Paste (Ctrl+V)
Undo (Ctrl+Z)
Redo (Ctrl+Shift+Z)
စာလံုးမ်ားရွာရန္၉
40
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Find All References (F7)
Select လုပ္ထားတဲ့ text ရဲ႕ reference ေတြ အားလံုးကို ျပေပးပါတယ္၉ သက္ဆုိင္ရာ code
ကို သြားခ်င္ရင္ reference ကုိ click လုပ္ျခင္းျဖင့္ အလြယ္တကူ ေရာက္ႏုိင္ပါတယ္၉ (ပံု ၀-၀)
ပံု ၀-၀
Block Comment
ေနဘဲ code ေတြကို select လုပ္ျပီး Block Comment ကို click ပါ၉ (ပံု ၀-၁) နဲ႕ (ပံု ၀-၂)
41
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Block Uncomment
Outlining
Function ၁ခုရတ
ွိ ယ္၉
Collapse လုပ္ထားတဲ့ code ဆိုရင္ expand လုပ္ေပးျပီး expand လုပ္ထားတဲ့ code ဆိုရင္
collapse လုပ္ေပးပါတယ္၉
- Expand All
- Collapse All
42
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.1.3. Designer Menu
Activity module
Class module
Code module
Service module
Main module မွအပ အျခား module ေတြအတြက္ ေအာက္ပါ option ၁ခုကို သံုးႏုိင္ပါတယ္၉
Remove Module
Hide Module
Modules tab မွာေတာ့ ျမင္ေနရဦးမွာပါ၉ Modules tab ကို သြားျပီး hide လုပ္ထားတဲ့ module ကုိ
43
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Choose Icon
ျပီး ျဖစ္ရမယ္၉
Package Name
ရဲ႕ ID ျဖစ္ပါတယ္၉
Unique Name
Application တစ္ခုရဲ႕ package name ဟာ အျခား application ရဲ႕ package name နဲ႕
မတူရပါဘူး၉ အျခား developer ေတြရဲ႕ package name နဲ႕ မတူရေလေအာင္ ကိုယ့္ရဲ႕ Internet
Allowed Characters
ေတြနဲ႕ဘဲ စေရးႏုိင္ပါတယ္၉ Package name မွာ အနည္းဆံုး dot (.) နဲ႕ ျခားထားတဲ့ component ၀ခု
Application ကုိ Google Play မွာ တင္လိုက္ျပီဆိုပါစို႕၉ Google Play မွာ application ရဲ႕
44
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
com.compumobile.appname ဆိုရင္ Google Play မွာ application ရဲ႕ URL က
https://play.google.com/store/apps/details?id=com.compumobile.appname
လို႕ျဖစ္ေနမွာပါ၉
Package name ဟာ application ရဲ႕ ID ျဖစ္တာေၾကာင့္ application ကို Google Play မွာ
အသစ္တစ္ခလ
ု ို႕ မွတ္ယူလိုက္မွာျဖစ္ပါတယ္၉ အရင္တင္ထားတဲ့ application ရဲ႕ new version လို႕
application ကို download ဆြဲထားတဲ့ user ေတြဟာ version အသစ္ကို auto update
မရႏုိင္ေတာ့ပါဘူး၉
Manifest Editor
မသံုးေတာ့ပါ၉
Project attributes နဲ႕ activity attributes ေတြ အေၾကာင္းရွင္းျပထားတဲ့ web page ကုိ
ေရာက္သြားပါမယ္၉
B4A code ေတြကို Java code အျဖစ္ေျပာင္းေပးျပီး device မွာ run ရန္၉ Run icon ကုိ
45
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ႏွိပ္တာနဲ႕ တူတူပါဘဲ၉ Debug (legacy) mode မွာ run ရင္ Objects folder ထဲမွာ (ပံု ဿ-၀၃)
ပံု ၀-၃
Compile ဘဲ လုပ္ပါတယ္၉ Device မွာ မ run ပါဘူး၉ ဒါေၾကာင့္ Device ကို PC နဲ႕
ခ်ိတ္ထားစရာ မလိုပါဘူး၉ Program မွာ error ရွိ၈ မရွိ စမ္းတဲ့အခါ သံုးသင့္ပါတယ္၉ Error မရွိေတာ့
Device မွာ install လုပ္ျပီးသား application ကို ျပန္ run ရန္၉ Compile လုပ္ျခင္း၈ install
လုပ္ျခင္း မရွိပါဘူး၉
Project ကို library file အျဖစ္ compile လုပ္ရန္၉ ဒီ library file ကုိ အျခား project ေတြ
မွာယူ သံုးႏုိင္ပါတယ္၉
46
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Compile (without signing)
Code ကုိ compile လုပ္ေပးပါတယ္၉ ဒါေပမယ့္ Objects folder ထဲမွာ apk file ကို
သံုးပါတယ္၉
IDE Options
- Tab Size
- Change Font
Code window ရဲ႕ font ကို ေျပာင္းရန္၉ Zawgyi-One font ေျပာင္းထားရင္ string ေတြကို
- Word Wrap
- Auto Save
Auto Save ကုိ check လုပ္ထားရင္ application ကုိ run တဲ့အခါ program code ကုိေရာ
47
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
- Show Tooltips During Typing
Show Tooltips During Typing ကို check လုပ္ထားရင္ method name ေရးျပီး
ကြင္းစေလးတစ္ခရ
ု ိုကလ
္ ိုက္တာနဲ႕ သက္ဆိုင္ရာ method အတြက္ ေရးရမယ့္ပံုစံကို နမူနာ
ပံု ၀-၄
ပံု ၀-၅
48
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Clean Project
Configure Paths
Take Screenshot
Size ကိုခ်ံဳ႕/ခ်ဲ႕ရန္
ပံု ၀-၆
Take Picture
49
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Save Picture
Orientation
တကယ္လုိ႕ IDE ဟာ debug mode မွာ ျဖစ္ေနရင္ ေတာ့ [Debug > Take Screenshot]
ပံု ၀-၇
About
50
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.1.7. Toolbar
Back
Forward
လြယ္ေအာင္ bookmark နဲ႕ မွတ္သားထားလို႕ ရပါတယ္၉ Code line မွာ cursor ခ်ျပီး bookmark
(Auto complete) လိ႕ု ေခၚပါတယ္၉ Ctrl + space bar ရိုက္တာနဲ႕တူတူပါဘဲ၉ ကို click
ရင္ B4A မွာသံုးသမွ် keyword ေတြကို ျပေပးတဲ့အတြက္ လိုအပ္တာ ေရြးယူလိုက္ယံုပါဘဲ၉ (ပံု ၀-ဿှ)
ပံု ၀-ဿှ
51
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၀-ဿဿ
ဒါေၾကာင့္ indentation ကုိ သံုးျပီး ေရးသင့္ပါတယ္၉ (ပံု ၀-ဿ၀) ကို ၾကည့္ပါ၉ Tab size = 2
နဲ႕ ေရးထားတာပါ၉ Tab size ဆိုတာ tab key တစ္ခါႏွိပ္ရင္ ေရြ႕သြားမယ့္အကြာအေှးပါ၉ Tab size
သတ္မွတ္ရန္ [Tools > IDE Options > Tab Size] ကို ေရြးရမယ္၉
ပံု ၀-ဿ၀
52
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တစ္လုိင္းထက္ပိုတဲ့ code ေတြကို indent လုပ္ခ်င္ရင္ code line ေတြကို (ပံု ၀-ဿ၁)
ပံု ၀-ဿ၁
Compile & Run လုပ္တဲ့အခါ ဘယ္ mode နဲ႕ compile & run မယ္ဆိုတာ ေရြးေပးရမယ္၉
(ပံု ၀-ဿ၂)
ပံု ၀-ဿ၂
Program မွာ code ေတြ သိပ္မ်ားသြားရင္ ကိုယ္သြားခ်င္တဲ့ sub routine ကုိ ရွာရခက္မယ္၉
ဒီကေန ကိုယ္သြားခ်င္တဲ့ sub routine ကို ေရြးုလိုက္တာနဲ႕ အဲဒီ sub routine ဆီ ေရာက္သြားမယ္၉
53
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2. Code Area
Project တုိင္းမွာ အနည္းဆံုး activity module တစ္ခု ရွိျပီး အမည္က „Main‟ ပါ၉ Project
Module တစ္ခုအတြက္ tab တစ္ခု ရွိတယ္၉ (Main module မွအပ က်န္ module မ်ားကို
သက္ဆုိင္ရာ module ရဲ႕ code ေတြကို editor (code area) မွာ ျမင္ရမယ္၉
ပံု ၀-ဿ၃
Main module ထဲမွာ pre-defined Region ၀ခု ရွိပါတယ္၉ Project Attributes နဲ႕ Activity
Attributes ပါ၉
အားလံုးအတြကအ
္ က်ိဳးသက္ေရာက္မွာျဖစ္ပါတယ္၉
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
54
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ApplicationLabel: မွာသတ္မွတ္ေပးလိုက္တဲ့ text ဟာ application ကုိ install လုပ္ျပီးေနာက္
#ApplicationLabel: GPSBasics
ပံု ၀-ဿ၄
VersionCode: 1
1.1
1.0.1 အစရွသ
ိ ျဖင့္ေပးႏုင
ိ ပ
္ ါတယ္၉
SupportedOrientations: Application ကုိ portrait mode (ေထာင္လိုက)္ မွာဘဲ run လိ႕ု ရေအာင္
„portrait‟, landscape mode (အလ်ားလိုက)္ မွာဘဲ run လိ႕ု ရေအာင္ „landscape‟, mode
55
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.1.2. Activity Attributes Region
#FullScreen: False
#IncludeTitle: True
#End Region
#FullScreen: မွာ False ထားရင္ (ပံု ၀-ဿ၅) အတုိင္း Full screen မဟုတ္ေတာ့ဘဲ status bar ကုိပါ
ျမင္ေနရပါမယ္၉ True ထားရင္ေတာ့ status bar ကို မျမင္ရေတာ့ဘဲ full screen ျဖစ္ေနပါ မယ္၉
(ပံု ၀-ဿ၆)
#IncludeTitle: ကို True လို႕သတ္မွတ္ရင္ B4A Example ဆိုတဲ့ title ကုိ ျမင္ရပါမယ္၉ False
56
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၀-၀ှ
#StartAtBoot: False
#End Region
2.2.2. Region
တစ္ခုမွာ sub routine တစ္ခုထက္မက ထည့္လို႕ရပါတယ္၉ ဥပမာ အေနနဲ႕ region တစ္ခုကို ျပထား
ပါတယ္၉ Region name က GPS ပါ၉ GPS region မွာ sub routine ၁ခု (Routine1, Routine2,
Routine3) ကိထ
ု ည့္ျပထားပါတယ္၉ Sub routine ထဲမွာ program code ေတြ ေရးရမွာပါ၉ (ပံု ၀-၀ဿ)
57
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၀-၀ဿ
2.2.3. Autocomplete
မလုပ
ိ ါဘူး၉ ကို္ယ္ေရးခ်င္တဲ့ keyword/variable name ရဲ႕ေရွ႕ဆံုးက စာလံုးအနည္းငယ္ရိုက္ျပီး Ctrl
+ space bar ပုတ္လုိက္ပါ၉ ဥပမာ ty လို႕ရိုက္ျပီး Ctrl + space bar ပုတ္လုိက္ပါ၉ Ty နဲ႕စတဲ့
variable, view နဲ႕ properties ေတြ အားလံုးကို ျပေပးတဲ့ popup menu ေပၚလာမယ္၉
ပံု ၀-၀၀
58
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.3.1. Icons
Keyword/method
Key constant
Function
Global variable
Local variable
Property
/object နဲ႕ဆုိင္တဲ့ property ေတြ method ေတြကို popup menu မွာ ျပပါလိမ့္မယ္၉ ကိုယ္လိုအပ္
ပံု ၀-၀၁
59
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.3.3. Autocomplete Event Subroutines
ဘို႕အတြက္ အေထာက္အကူ ရပါတယ္၉ Sub လို႕ရိုက္ျပီး space တစ္ခုျခားပါ၉ ျပီးရင္ tab key ကုိ
ပံု ၀-၀၂
လိုအပ္တဲ့ type ကုိ ေရြးျပီး enter ေခါက္လုိက္ပါ (ဥပမာ Button)၉ ကိုယ္ေရြးလုိက္တဲ့ type
မွာ ရႏိင
ု ္တဲ့ event ေတြကို (ပံု ၀-၀၃) မွာကဲ့သို႕ ျမင္ရပါလိမ့္မယ္၉ လိုအပ္တာတစ္ခုကို ေရြးျပီး enter
ပံု ၀-၀၃
Sub EventName_Click
End Sub
60
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
EventName ေနရာမွာ အဲဒီ event ကုိျဖစ္ေပၚေစတဲ့ source object (ဥပမာ Button1) ရဲ႕
event name ကုိ ေရးေပးရမယ္၉ Event name နမူနာတစ္ခုကို (ပံု ၀-၀၄) မွာ ျပထားပါတယ္၉
ပံု ၀-၀၄
Button1 ရဲ႕ event name က btnCM ျဖစ္ပါတယ္၉ ဒါေၾကာင့္ Sub EventName_Click ရဲ႕
Sub btnCM_Click
End Sub
Code area မွာ object name ေရးျပီး dot (.) ခ်လိုက္တာနဲ႕ (ပံု ၀-၀၅) မွာ ျပထား
61
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၀-၀၅
2.2.5. Context Menu (Popup Menu)
Code area ရဲ႕လြတ္တဲ့ေနရာမွာ right click လုပ္ရင္ (ပံု ၀-၀၆) မွာျမင္ရတဲ့အတုိင္း context
menu တစ္ခုေပၚလာပါလိမ့္မယ္၉
ပံု ၀-၀၆
(ပံု ၀-၀၇)
62
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၀-၀၇
right click လုပ္ပါ၉ Popup menu ေပၚလာရင္ Goto Sub Declaration ကုိ ေရြးပါ၉ (ပံု ၀-၁ှ)
ပံု ၀-၁ှ
63
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.6. Highlighting Occurrences of Words
light လုပ္ေပးပါတယ္၉ (ပံု ၀-၁ဿ) မွာ Lat ကုိ select လုပ္လိုက္တာနဲ႕ Lat ေတြ အားလံုးကို high
light လုပ္ျပေပးပါတယ္၉
ပံု ၀-၁ဿ
2.2.7. Breakpoints
Program ကုိ အစအဆံုး မ run ေစဘဲ breakpoint သံုးျပီး ရပ္ခ်င္တဲ့ code line မွာ ရပ္ခိုင္း
လို႕ ရပါတယ္၉ Debug (legacy) နဲ႕ Debug (rapid) mode တို႕မွာသာ သံုးႏုိင္ပါတယ္၉ ရပ္ခ်င္တဲ့
code line ေဘးက margin ေပၚမွာ click လိုက္ရင္ breakpoint တစ္ခု ထည့္ျပီးျဖစ္ပါတယ္
(ပံု ၀-၁၀)၉ Breakpoint တစ္ခုထက္မကလည္း ထည့္လို႕ရပါတယ္၉ Breakpoint ကုိ သံုးျပီး error ကို
ေတြမွာေတာ့ ထားလို႕မရပါဘူး၉
ပံု ၀-၁၀
64
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.8. Color Picker
ပါတယ္၉ Code window မွာ လြတ္တဲ့ေနရာ right click လုပ္ပါ၉ Popup menu (ပံု ၀-၁၁) မွာ „Show
2.2.9. Debugging
Debug
Release
o Release mode
o Release (obfuscated)
65
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.2.9.1. Debug (legacy) Mode
အျခားကို ျဖန္႕ေှမယ့္ application ကုိ Debug (legacy) mode နဲ႕ မ run သင့္ပါဘူး၉
Project ကုိ Debug (rapid) mode မွာ run ျခင္းအားျဖင့္ run ေနစဥ္အခ်ိန္အတြင္းမွာဘဲ
program code ကုိ ျပင္ဆင္၈ save လုပ္ျပီး code အသစ္နဲ႕ဆက္ run ႏုိင္ပါတယ္၉
ရမယ္၉
Release
Release (obfuscated)
Program ကုိ compile လုပ္စဥ္မွာ Java code ေတြကို generate လုပ္ေပးပါတယ္၉ Java
compiler က Java code ေတြကို compile လုပ္ျပီး Dalvik (Android byte code format) အျဖစ္
ေျပာင္းေပးပါတယ္၉ Delvik byte code ကေန Java code ကုိ ေျပာင္းႏုိင္တဲ့ (decompile လုပ္ႏိုင္တ)ဲ့
tool ေတြရွိပါတယ္၉ ဒီနည္းနဲ႕ ကိုယ့္ application ရဲ႕ code ေတြကို အျခားသူေတြ ရသြားႏုိင္ပါတယ္၉
Release (obfuscated) mode နဲ႕ run ျခင္းအားျဖင့္ decompiled code ေတြကို ဖတ္ရခက္ခဲေအာင္၈
ရႈပ္ေထြးသြားေအာင္ လုပ္ႏုိင္ပါတယ္၉
2.4. Tabs
ပံု ၀-၁၃
66
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
2.4.1. Modules Tab
Project တစ္ခမ
ု ွာ module တစ္ခုမက ပါႏုိင္ပါတယ္၉ Modules tab ကိုေရြးလုိက္ရင္ project
အတြင္း ရွိသမွ် module ေတြကို detail area မွာ ျပေပးပါလိမ့္မယ္၉ Module name ေတြေအာက္မွာ
ပံု ၀-၁၄
Module တစ္ခုကို click လုိက္ရင္ အဲဒီ module ရဲ႕ code ေတြကို code window မွာ
ျပပါလိမ့္မယ္၉ Subroutine တစ္ခုကို click လုိက္ရင္ cursor ဟာ အဲဒီ subroutine code ေတြဆီကုိ
ေရာက္သြားပါလိမ့္မယ္၉
ပံု ၀-၁၅
67
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Project ထဲ ဖုိင္ေတြထည့္ခ်င္ရင္ Add Files ကို click ပါ၉ မည္သည့္ဖုိင္အမ်ိဳးအစား (layout,
Program ကို run ေနစဥ္မွာ program က generate လုပ္လိုက္တဲ့ comment ေတြကို Logs
tab ရဲ႕ detail area မွာျပပါတယ္၉ Program မွာ Log (“Hello”) လို႕ေရးျပီး run ရင္ detail area မွာ
Hello လို႕ျပပါလိမ့္မယ္၉
ပံု ၀-၁၆
Filter ကို check လုပ္ထားရင္ ကိုယ့္ program နဲ႕ဆုိင္တဲ့ message ေတြကိုသာ ျမင္ရမွာပါ၉
Program ကုိ run ျပီး Logs ရဲ႕ detail area မွာ ဘာမွမျမင္ရေသးရင္ „Connect‟ button ကုိ
ႏွိပ္ပါ၉
B4A မွာ configure လုပ္ထားတဲ့ library file ေတြကို ျပပါလိမ့္မယ္၉ (ပံု ၀-၁၇)
ပံု ၀-၁၇
68
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 3
BASIC Language
software မွာ operating system, middleware နဲ႕ key application ေတြပါှင္ပါတယ္။ Android
ကိုစတင္ develop လုပ္ခဲ့တာကေတာ့ Android Inc. ပါ။ 2005 ခုႏွစ္မွာ Google Inc. ဟာ Android
ကိှ
ု ယ္ယူခပ
ဲ့ ါတယ္။
တစ္ခုျဖစ္ပါတယ္။
Dim A As Int
အတြက္သတ္မွတ္ထားတဲ့ key word ပါ။ A မွာ ထည့္မယ့္ data type ဟာ integer data type
ျဖစ္တယ္လို႕ declare လုပ္လိုက္တာပါ။ Variable ထဲမွာ data ကို assign မလုပ္မီ variable ကို အရင္
70
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Variable type ၀မ်ိဳးရွိပါတယ္။
Primitive နဲ႕
Non-primitive ျဖစ္ပါတယ္။
ဇယား (၁-ဿ)
Byte, Shrot, Int, Long တို႕ဟာ integer type ေတြျဖစ္ပါတယ္။ Integer ဆိုတာ
71
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Byte type အျဖစ္ declare လုပ္ထားတဲ့ variable ဟာ 8 bit (-128 ကေန 127 ထိ)
Primitive type ေတြဟာ အျခား sub ေတြကို ေခၚတဲ့အခါ၊ ဒါမွမဟုတ္ အျခား variable
တစ္ခုထဲကို assign လုပ္တဲ့အခါ variable ထဲမွာရွိတဲ့ value ကို pass လုပ္ပါတယ္။ ဥပမာ
A = 12 End Sub
S2(A)
Log(A)
End Sub
ေတြျဖစ္ပါတယ္။
Dim A As Int
A = 12
S2(A)
72
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(B As Int)
Log (B * 2)
ေတြကိုဆက္လုပ္ပါမယ္။
Log (A)
အျခား sub ေတြဆီ variable ကို pass လုပ္တဲ့အခါ variable ထဲက value ကို copy
Example 3.1
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#FullScreen: False
73
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
S1
End Sub
Sub Activity_Resume
End Sub
End Sub
Sub S1
Dim A As Int
A = 12
S2(A)
Log (A)
End Sub
74
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub S2(B As Int)
Log (B * 2)
End Sub
primitive type variable ေတြကို sub တစ္ခုဆီ pass လုပ္တဲ့အခါမွာျဖစ္ေစ၊ variable တစ္ခုထဲကို
ဆီ array တစ္ခုကို pass လုပ္ပါ။ S2 ထဲမွာ array value ကိုေျပာင္းလိုက္တာနဲ႕ S1 ထဲက array
Example 3.2
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#FullScreen: False
#IncludeTitle: True
#End Region
75
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Process_Globals
End Sub
Sub Globals
End Sub
S1
End Sub
Sub Activity_Resume
End Sub
End Sub
Sub S1
A = Array As Int(1, 2, 3, 4, 5)
S2(A)
Log (A(0))
End Sub
B(0) = B(0) * 2
76
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Log (B(0))
End Sub
အထက္ပါ program ကုိ run ရင္ မူလက A(0) မွာ 1 ျဖစ္ပါတယ္။ S2 ဆီ pass လုပ္လိုက္ရင္
B(0) မွာ 1 ေရာက္သြားပါမယ္။ B(0) ကို 2 နဲ႕ေျမွာက္ျပီး B(0) မွာျပန္ထည့္ပါ။ အခုဆိုရင္ B(0) မွာ 2
Variable name ကုိၾကိဳက္ရာေပးႏုိင္ပါတယ္။ ဒါေပမယ့္ reserved word ေတြ နဲ႕ key word
ေတြေတာ့မေပးရပါဘူး။ ဥပမာ variable name ကုိ Int, Sub အစရွိတဲ့ B4A မွာသံုးေနတဲ့ key word
birthdate လို႕ေပးတာမ်ိဳးဘဲျဖစ္သင့္ပါတယ္။
Variable declare လုပ္တဲ့အခါ Dim ဆိုတဲ့ keyword ေနာက္မွာ variable name နဲ႕ As
Dim i As Int
Dim j As Int
77
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim k As Int
Dim ch As Char
Dim i, j, k As Int
Dim i = 0, j = 2, k = 5 As Int
Dim txt = "test" As String, value = 1.05 As Double, flag = False As Boolean
Value တစ္ခုကို variable ထဲ assign လုပ္ခ်င္ရင္ variable name ကိုအရင္ေရးျပီး „=‟ ေရးပါ။
78
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Capital = 1200.00
LastName = "SMITH"
ch = „A‟
numeric value ျဖစ္လို႕ပါ။ ဒါေပမယ့္ LastName ထဲကို assign လုပ္တဲ့ SMITH ကုိေတာ့ “”
ပံု ၁-ဿ
79
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Two Dimensional Array
Row ၁ခု၊ column ၁ခု ပါတဲ့ two dimensional array နမူနာတစ္ခုကို (ပံု ၁-၀)
0 1 2 Matrix (2, 1)
ပံု ၁-၀
ပံု ၁-၁
80
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Three dimensional array နမူနာတစ္ခုကို (ပံု ၁-၁) မွာၾကည့္ပါ။ Declare လုပ္ရမယ့္
ပံုစက
ံ ေတာ့ ေအာက္ပါအတုိင္းျဖစ္ပါတယ္။
သို႕မဟုတ္
လို႕လည္းေပါင္းေရးႏိုင္ပါတယ္။
NbPers ကုိ Int အျဖစ္ declare လုပ္ျပီးေနာက္ NbPers ထဲမွာ 10 ကို assign
လုပ္လုိက္ပါတယ္။
81
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim LastName(NbPers) As String Dim LastName(10) As String
သည္ နဲ႕တူတူဘဲျဖစ္ပါတယ္။
သည္
view ေတြကို Buttons() array ထဲထည့္ပါမယ္။ အရင္ဆံုး button ေတြကို declare လုပ္ရမယ္။
82
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim Buttons() As Button
„Type‟ keyword ကိုသံုးျပီး ကိုယ္ပိုင္ data type (structure) ေတြ create လုပ္ႏိုင္ပါတယ္။
Type variable တစ္ခုကို ဘယ္ module ကမဆိုေခၚသံုးႏုိင္ပါတယ္။ ဒါေၾကာင့္ Main module ထဲက
LastName, FirstName, Address, City အစရိွတဲ့ variable ေတြကို ေပါင္းျပီး „Person‟ type
အျဖစ္သတ္မွတ္လုိက္ပါတယ္။
String)
ျပီးရင္ variable၀ခု User1 နဲ႕ User2 ကို Person type variable အျဖစ္ declare လုပ္မယ္။
User1.LastName = “Tun”
User1.FirstName = “Lwin”
User1.City = “Yangon”
83
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
User2 မွာလည္းေအာက္ပါအတုိင္း data ေတြ assign လုပ္ပါမယ္။
User1.LastName = “Sein”
User1.FirstName = “Than”
User1.City = “Bago”
Student(1).LastName = “Maung”
Student(1).FirstName = “Aye”
Student(2).LastName = “Phyu”
Student(2).FirstName = “Win”
Type variable တစ္ခုကို (type တူတ)ဲ့ အျခား variable တစ္ခုထဲ assign လုပ္ႏုိင္ပါတယ္။
ဥပမာ
Dim IT As Person
IT= Student(1)
84
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.1.4. Casting
programmer ကုယ
ိ ္တိုင္ code ေရးျပီး cast လုပ္ေပးျခင္းကိုေခၚပါတယ္။ လုပ္နည္းကေတာ့
ေျပာင္းခ်င္တဲ့ type နဲ႕ declare လုပ္ထားတဲ့ variable ထဲ object ကို assign လုပ္ရန္သာျဖစ္ပါတယ္။
ဥပမာ Sender ဆိုတာ object တစ္ခုျဖစ္ပါတယ္။ ဒီ object ကုိ Button type variable ထဲကို assign
လုပ္ျခင္းျဖင့္ Sender object ကို Button type အျဖစ္ cast လုပ္လိုက္ပါတယ္။ ဒါကို explicitly cast
လုပ္တယ္လို႕ေခၚပါတယ္။
btn = Sender
3.1.5. Scope
variable အျဖစ္ declare မလုပ္ႏုိင္ပါဘူး။ ဥပမာ view ေတြကို process variable အျဖစ္ declare
85
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Activity တစ္ခု destroy ျဖစ္သြားရင္ garbage collector က activity ထဲက view ေတြကိုပါ
ပါထည့္ေပးရမယ္။ ဥပမာ Main module ထဲမွာ process variable MyVar ကို ေအာက္ပါအတုိင္း
declare လုပ္ထားတယ္ဆုိပါေတာ့။
Sub Process_Globals
End Sub
MyVar = "Text"
Main.MyVar = "Text"
လို႕ေရးရမယ္။
variable ေတြကို Sub Globals အတြင္းမွာ declare လုပ္ရပါတယ္။ သူ႕ကို declare လုပ္ထားတဲ့
activity အတြင္းမွာဘဲသံုးႏုင
ိ ္တာေၾကာင့္ private variable လို႕ေခၚပါတယ္။ Activity ရွိေနသမွ် ဒီ
variable ေတြတည္ရွိေနမွာပါ။
86
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.1.5.3. Local Variable
အဲဒီ module ကေတာ့ activity module ပါ။ Module ရဲ႕အမည္ကိုေတာ့ Main လို႕ေခၚပါတယ္။
Activity module မွာေအာက္ပါ region ေတြနဲ႕ subroutine ေတြပါဝင္ပါတယ္။ Program ရဲ႕ flow
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
87
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Globals
End Sub
End Sub
Sub Activity_Resume
End Sub
End Sub
3.3. Expression
88
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဇယား (၁-၀)
operator ကိုေဆာင္ရြကရ
္ မယ္ဆိုတဲ့ သတ္မွတ္ခ်က္ျဖစ္ပါတယ္။ Level 1 operator ကုိအရင္
89
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Equal to (=)
x=y
(x ရဲ႕ value နဲ႕ y ရဲ႕ value ညီသလားစစ္တာပါ။ ညီရင္ evaluate result က True ေပါ့)
x<>y
(x ရဲ႕ value နဲ႕ y ရဲ႕ value မညီဘူးလားဆိုတာစစ္တာပါ။ မညီရင္ evaluate result က True ေပါ့)
x> y
x< y
x >= y
x <= y
90
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Relational expression မွာ operator ဟာ entity ႏွစ္ခုရဲ႕ ဆက္စပ္မႈကိုစစ္ေဆးပါတယ္။
ကေတာ့ True/False ျဖစ္ပါမယ္။ အထက္က ဥပမာမွာ 5 = 5 ကို evaluate လုပ္ရင္ result က True
ေပါ့။ 4 >= 3 expression ကုိ evaluate လုပ္ရင္ result က True ျဖစ္မယ္ေနာ္။ 6 = 5 ကို evaluate
Evaluate လုပ္တဲ့အခါ True သို႕မဟုတ္ False ရတဲ့ expression ကုိ boolean expression
တို႕ျဖစ္ပါတယ္။
Z = X Or Y
Z = X And Y
ဆိုတဲ့ expression မွာ X ေရာ Y ပါ True ျဖစ္မွ Z ဟာ True ျဖစ္ပါမယ္။ ဇယား (၁-၁) မွာၾကည့္ပါ။
ဇယား (၁-၁)
91
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Not ကိုေလ့လာၾကည့္ရေအာင္။ X ဟာ True ျဖစ္ရင္
Y = Not(X)
ဆိုတဲ့ expression မွာ Y ဟာ False ျဖစ္မယ္။ True ကို Not လုပ္ရင္ False, False ကို Not လုပ္ရင္
True ျဖစ္ပါတယ္။
If test1 Then
code1
End If
ျဖစ္ရင္ဘာမွမလုပ္ပါဘူး။ ဥပမာ
Dim a, b As Int
b=0
If b = 0 Then
Log(“b is 0”)
End If
„b = 0‟ expression True ျဖစ္ရင္ „Log(“b is 0”)‟ code ကုိ execute လုပ္ပါတယ္။ False
ျဖစ္ရင္ ဘာမွမလုပ္ပါဘူး။
92
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.4.2. If-Then-Else Structure
If test1 Then
code1
Else
code2
End If
ကုိေဆာင္ရြက္ပါမယ္။ ဥပမာ
Dim a, b As Int
b=0
If b = 0 Then
Log(“b is 0”)
Else
End If
„b = 0‟ expression True ျဖစ္ရင္ „Log(“b is 0”)‟ code ကုိ execute လုပ္ပါတယ္။ False
93
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ေနာက္ structure တစ္ခုကေတာ့
code1
… …
… …
…
…
Else
„test1‟ „test2‟ „…‟ „…‟ တစ္ခုမွ true မျဖစ္ရင္ „code‟
code
ကို execute လုပ္မယ္။
End If
ဥပမာ
Dim a, b As Int
a = 1, b = 2
If a < b Then
Else
End If
94
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.4.3. Select – Case
„If - Else - If‟ အစား „Select - Case‟ ကုိ အသံုးျပဳႏုိင္ပါတယ္။ Select - Case ရဲ႕ structure
ကေတာ့ ေအာက္ပါအတုိင္းျဖစ္ပါတယ္။
Select test
Case 0 : code1
Case 1 : code2
Case 2 : code3
End Select
Test ထဲက value ဟာ 0 ျဖစ္ရင္ code1, 1 ျဖစ္ရင္ code2, 2 ျဖစ္ရင္ code3 ကို execute
လုပ္ပါတယ္။ ဥပမာ
temp = 1
Select temp
Case 0 : “temp is 0”
Case 1 : “temp is 1”
Case 2 : “temp is 2”
End select
„temp‟ ရဲ႕ value ကို Case ေနာက္က value နဲ႕တိုက္စစ္မယ္။ တူတဲ့ Case ရဲ႕ code ကုိ
execute လုပ္မယ္။ အထက္ပါ example မွာဆုိရင္ Case 1 ကုိ execute လုပ္မွာျဖစ္တဲ့အတြက္ log
95
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.5. Loop Structures
ကုိသံုးရပါမယ္။
For i = n1 To n2 Step n3
„Specific code
Next
„i' ကို incremental variable လို႕ေခၚပါတယ္။ „n1‟ ကေတာ့ initial value ပါ။ „n2‟ က final
i = n1
i = i + n3
If i <= n2
5. (i <= n2) သည္ True ျဖစ္ရင္ program ဟာ For နဲ႕ Next ၾကားက code ေတြကိုထပ္မံ
execute လုပ္ပါတယ္။
6. (i <= n2) သည္ False ျဖစ္ရင္ေတာ့ program ဟာ For - Next loop ကေနထြက္သြားပါ
မယ္။
96
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တကယ္လို႕ Step ရဲ႕ value ဟာ +1 ျဖစ္ရင္ေတာ့ Step ဆိုတဲ့ keyword
Log(“Hello”) Log(“Hello”)
Next Next
For i = n3 To 0 Step -1
Log(“Hello”)
Next
အထက္ပါ code မွာ စစခ်င္း i ထဲမွာ n3 ကုိထည့္မယ္။ Logs area မွာ Hello ကုိထုတ္ျပမယ္။
Dim A As Int
A=0
For i = 0 To 10
A=A+1
If A = 2 Then Exit
Next
97
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အထက္ပါ example ကိုၾကည့္ရင္ A ထဲမွာ 0 ထည့္ထားပါတယ္။ For loop အစမွာ i ထဲကို 0
ထဲျပန္ထည့္တဲ့အတြက္ A = 1 ျဖစ္ပါတယ္။
(A = 2) သည္ True ျဖစ္သြားတာေၾကာင့္ Exit code ကုိ execute လုပ္ပါတယ္။ Exit က loop
„Specific code
Next
အထက္ပါ code မွာ „n‟ ဆိုတာ variable/object ျဖစ္ပါတယ္။ Type ဆုိတာကေတာ့ „n‟ ရဲ႕
type ပါ။ Array ဆိုတာကေတာ့ values/objects ေတြပါတဲ့ array ေပါ့။ For-Each loop
ရဲ႕အလုပ္လုပ္ပံုကေတာ့ေအာက္ပါအတိုင္းျဖစ္ပါတယ္။
98
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
1. စစခ်င္းမွာ n ထဲကို Array ရဲ႕ first element ထည့္ပါတယ္။
n = Array(0)
3. Next ကိုေရာက္ရင္ n ရဲ႕ value ဟာ Array ရဲ႕ last element ထဲက value
ျဖစ္ျပီလားစစ္ပါတယ္။
4. Last element ရဲ႕ value မဟုတ္ေသးဘူးဆိုရင္ n ထဲကို Array ရဲ႕ second element
ကိုထည့္ပါတယ္။ ျပီးရင္ For နဲ႕ Next ၾကားက code ေတြကို execute လုပ္ပါတယ္။
လုပ္ပါမယ္။
Dim Numbers() As Int Numbers ဆိုတဲ့ Int type array တစ္ခု declare
လုပ္ပါတယ္။
Dim Sum As Int Sum ဆိုတဲ့ Int type variable တစ္ခု declare
လုပ္ပါတယ္။
ေတြရွိေနမယ့္အေနအထားက
ေအာက္မွာျပထားတဲ့အတုိင္း ျဖစ္ပါတယ္။
99
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
For Each n As Int In Numbers စစခ်င္း n ထဲမွာ Array ရဲ႕ first element
Sum = 1 ျဖစ္သြားပါျပီ။
ျဖစ္ပါမယ္။
Sum = 0
For i = 0 To Numbers.Length - 1
Next
3.5.3. Do – Loop
100
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Do While test
„code
Loop
statement ကုိ execute လုပ္မယ္။ (i < 10) expression True ျဖစ္ေနသမွ် Do While loop
ကုိပတ္ေနမယ္။
Dim i As Int
i=0
Do While i <10
i=i+1
Loop
Do While i <10
i=i+1
Loop
101
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Do Until
Do Until ကေတာ့ „test‟ expression သည္ False ျဖစ္ေနသမွ် code ကုိ execute လုပ္မယ္။
Do Until test
„code
Loop
Dim i As Int
i=0
3.6. Sub
သိပ္မ်ားရင္ေတာ့ ဖတ္ရတာခက္ခႏ
ဲ ိုင္ပါတယ္။
102
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.6.1. Declaring
End Sub
Sub ဆုိတဲ့ keyword နဲ႕စရမယ္။ ေနာက္မွာ Sub ရဲ႕ name ပါရမယ္ (ဥပမာ CalcInterest)။
လိုအပ္ခ်က္ေပၚမူတည္ျပီး parameter list နဲ႕ return type ေတြထည့္ေပးရပါတယ္။ End Sub ဆိုတဲ့
3.6.2. Naming
Sub တစ္ခုအတြင္းက code ေတြကို execute လုပ္ခ်င္ရင္ အဲဒီ sub ကို ေခၚရပါတယ္။
Sub Bank
End
103
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တစ္နည္းအားျဖင့္ CalcInterest Sub ထဲက code ေတြကို execute လုပ္ခိုင္းတာပါဘဲ။
CalcInterest(1235, 5.2)
3.6.4. Parameter
Sub တစ္ခုက data ေတြကို အျခား sub ဆီပို႕ေပးလို႕ရပါတယ္။ အျခား sub ကပို႕လာတဲ့
End Sub
ေတြျဖစ္ပါတယ္။ Double ကေတာ့ အဲဒီ parameter ေတြရဲ႕ type ပါ။ အျခား sub ကေန
ထဲေရာက္ပါတယ္။
Sub တစ္ခုဟာ သူ႕ကို ေခၚတဲ့ calling sub ဆီကို value တစ္ခုျပန္ပို႕ေပးႏုိင္ပါတယ္။ ဒါကို
ျပန္မယ္ဆိုရင္ return value ဟာ သူ႕ကို ေခၚခဲ့တဲ့ sub A ဆီေရာက္မယ္။ Return ျပန္မယ့္ value
ကုိသံုးရမယ္။ Return value ရဲ႕ type ကို sub declaration ရဲ႕ parameter list ေနာက္မွာေရးရမယ္။
ဥပမာ
104
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub CalcInterest(Capital As Double, Rate As Double) As Double
End Sub
Sub CalcInterest ထဲမွာ Capital * Rate / 100 ကိုတြက္ပါတယ္။ အေျဖ 64.22 ရပါတယ္။
အေျဖကို retun ျပန္ပါတယ္။ Return ျပန္တယ္ဆိုတာ value ကုိ calling sub ဆီပို႕တာပါ။ Calling
sub က Bank ျဖစ္ပါတယ္။ ဒါေၾကာင့္ value (64.22) ဟာ Bank ဆီေရာက္သြားပါတယ္။ Sub Bank
မွာ return value (64.22) ကုိ Interest ထဲထည့္ပါတယ္။ ျပီးရင္ ထုတ္ၾကည့္ပါတယ္။ Logs area မွာ
64.22 လုိ႕ျမင္ရမွာျဖစ္ပါတယ္။
Sub Bank
Log(Interest)
End Sub
End Sub
Log(Interest)
End Sub
ဥပမာ MyModule ထဲက CalcInterest sub ကုိ အျခား module ကေန ေခၚခ်င္ရင္
MyMoudle.CalcInerest လို႕ေရးရမယ္။
105
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.7. Event
Android မွာ user interface object ေတြကို view လို႕ေခၚပါတယ္ (ဥပမာ Button, Label,
ဇယား (၁-၂)
106
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အသံုးမ်ားတဲ့ event ေတြကို ေအာက္မွာရွင္းျပေပးထားပါတယ္။
Click
User က view တစ္ခုကို click လုပ္လုိက္ရင္ Click Event ျဖစ္ေပၚပါတယ္။ ဥပမာ Button
တစ္ခုရွိမယ္။ Button ရဲ႕ event name က Button1 ဆိုပါေတာ့။ အဲဒီ Button ကုိ click လိုက္ရင္
Click event ျဖစ္ေပၚလာပါမယ္။ Click event ကို handle လုပ္မယ့္ code ကုိ Button1_Click event
sub အတြင္းမွာေရးေပးရပါမယ္။ Button1 ကုိ click ရင္ Logs area မွာ Hello လို႕ေပၚေစခ်င္ပါက
ေအာက္ပါအတုိင္းေရးေပးရပါမယ္။
End Sub
LongClick
Sub Button1_LongClick
End Sub
User က screen ကိုလက္နဲ႕ထိရင္ Touch event ျဖစ္ေပၚပါတယ္။ Touch event မွာ action
၁မ်ိဳးရွိပါတယ္။
action)
107
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Activity.Action_UP (User က screen ကိုလက္နဲ႕ထိထားရာကေန လက္ကို screen
မွခြာလိုက္တဲ့အခါျဖစ္ေပၚလာတဲ့ action)
နဲ႕စစ္ရမယ္။
' Your code for DOWN action Action Down ဆိုရင္ ဒီ code ကုိ execute
လုပ္မယ္
' Your code for MOVE action Action Down ဆိုရင္ ဒီ code ကုိ execute
လုပ္မယ္။
' Your code for UP action Action Up ဆိုရင္ ဒီ code ကုိ execute လုပ္မယ္
End Select
108
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
CheckChanged (Checked As Boolean)
Else
End If
End Sub
ဆုိတာကေတာ့ user ႏွိပ္လိုက္တဲ့ key ရဲ႕ code ပါ။ KeyPress event ျဖစ္ေပၚရင္ Boolean type
variable တစ္ခက
ု ုိ return ျပန္ပါတယ္။ ေနာက္ထပ္ေဆာင္ရြက္စရာမလိုေတာ့ရင္ False ကုိ return
109
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု (၁.၂)
message box ကုိျပပါမယ္။ ပိတ္မွာေသခ်ာရင္ user က Yes ကုိေရြးရမယ္။ Yes ကိုေရြးရင္ program
မဟုတ္ရင္မလုပ္ဘူး)
110
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(Message box တစ္ခုေပၚေစျပီး user ေရြးလိုက္တဲ့ response value ကို Answ
ေရာက္မယ္)
Return False
Else
return ျပန္ပါတယ္)
Return True
End If
End If
End Sub
3.8. Library
Library တစ္ခုကိုအသံုးျပဳဘို႕လိုအပ္ရင္
ရွိုျပီးသား library ဆိုရင္ Libs tab ကေနကိုယ္သံုးခ်င္တဲ့ library ကုိ check လုပ္ပါ။
ထဲထည့္ပါ။
111
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.8.1. Standard Library
Basic4android\Libraries ထဲမွာေတြ႕ႏုိင္ပါတယ္။
Example 3.3
Phone library မွ object ေတြကိုသံုးျပီး ဖုန္းေခၚျခင္း၊ SMS ပို႕ျခင္း၊ web site ဖြင့္ျခင္း၊ eMail
ပုိ႕ျခင္းတုိ႕ကိုနမူနာမ်ားနဲ႕ျပပါမယ္။ Libs tab ကေန Phone library ကုိ check လုပ္ထားပါ။ Designer
ကေန layout တစ္ခုဖန္တီးပါ။ Layout မွာ button တစ္ခုထည့္ျပီး layout name ကုိ Layout1
Activity.LoadLayout(“Layout1”)
End Sub
Calling Phone
Sub Button1_Click
Dim pc As PhoneCalls
StartActivity(pc.Call("09250386961"))
End Sub
112
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sending SMS
Sub Button1_Click
Sms1.Send("0973140515","Hello!")
End Sub
Sub Button1_Click
Dim pi As PhoneIntents
StartActivity(pi.OpenBrowser("http://www.facebook.com"))
End Sub
Sending Email
Sub Button1_Click
113
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Message.Body = "Good Morning" [ေရးခ်င္တဲ့ text]
StartActivity(Message.GetIntent)
End Sub
အထက္ပါ error message ျမင္ရရင္ေတာ့ Libs tab ကေနျပန္စစ္ပါ။ လိုအပ္တဲ့ library ကုိ
check မလုပ္ထားခဲ့လို႕ပါ။
String ဆိုတာ တစ္ခုထက္ပိုတဲ့ character ကိုေခၚတာပါ။ ဥပမာ „h‟ ဆိုတာ character, „i‟
txt = "123,234,45,23"
CharAt(Index)
txt = “hello”
114
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ch = txt.CharAt(0) ဆိုရင္ ch ထဲကို h ေရာက္လာမယ္။ txt ရဲ႕ position 0 မွာ h
ရွိေနလို႕ပါ။
ရွိေနလို႕ပါ။
CompareTo (Other)
String တစ္ခုကို အျခား string တစ္ခုနဲ႕ ႏိႈင္းယွဥ္ပါတယ္။ တူရင္ True ကုိ return
ျပန္ပါတယ္။ ဥပမာ
s1 = “I go to school.”
s2 = “I go to school.”
s1.CompareTo(s2)
Contains (SearchFor)
s1 = “Hello World!”
s2 = “Hello”
s1.Contains(s2)
StartsWidth(Prefix)
ဥပမာ
s1 = “I go to school.”
s2 = “I”
115
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
s1.StartsWidth(s2)
EndsWith(Suffix)
ျပန္ေပးပါတယ္။ ဥပမာ
s1 = “I go to school.”
s2 = “school.”
s1.EndsWidth(s2)
EqualsIgnoreCase(Other)
s1= “APPLE”
s2 = “apple”
s1.EqualsIgnoreCase(s2)
GetBytes(Charset)
Charset ထဲက string ကို byte array အျဖစ္ encode လုပ္ပါတယ္။ ဥပမာ
Dim ba () As Byte
ba = GetBytes(Charset)
IndexOf(SearchFor)
ဥပမာ
116
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim i As Int
s2 = “device”
i = s1.IndexOf(s2)
Dim i As Int
s2 = “device”
i = s1.IndexOf2(s2, 22)
LastIndexOf (SearchFor)
Dim i As Int
s2 = “device”
117
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
i = s1.LastIndexOf(s2)
Length
Dim s2 As String
Dim i As Int
s2 = “device”
i = s2.Length
txt = "123,234,45,23"
Substring (BeginIndex)
ဥပမာ
118
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim text, subtext As String
subtext = text.SubString(6)
မူလ string ထဲက BeginIndex နဲ႕စျပီး EndIndex မွာဆံုးတဲ့ string ကုိ return
ျပန္ေပးပါတယ္။ ဥပမာ
subtext = text.SubString2(6,8)
ToLowerCase
Dim u, l As String
u = “HELLO”
l = ToLowerCase(u)
ToUpperCase
119
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim u, l As String
l = “hello”
u = ToUpperCase(l)
Trim
ျပန္ေပးပါတယ္။ ဥပမာ
s1 = “ I go to school. ”
s2 = s1.Trim
ေတြကိုဖ်က္ေပးပါတယ္။
Number Formatting
သံုးႏုိင္တယ္)
ျဖစ္ေနတဲ့အတြက္ + 10 ကိုပါ ()
ထည့္ေရးရပါတယ္)
120
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
NumberFormat2(Number As Double, MinimumIntegers As Int, MaximumFractions As
3.10. Timer
ဒါေၾကာင့္ activity ကို pause လုပ္ထားရင္ Timer ကုိ disable လုပ္ထားသင့္တယ္။ resume
Initialize
Timer ကို parameter ၀ခုနဲ႕ initialize လုပ္ရမယ္။ Event name နဲ႕ interval ပါ။
ဥပမာ
Timer1.Initialize("T1", 1000)
Interval
ဥပမာ
121
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Enabled
Timer1.Enabled = True
Tick
ျပည့္သြားတိုင္း Tick event ျဖစ္ေပၚပါတယ္။ Timer ကို Process_Global routine မွာ declare
လုပ္ရမယ္။
Sub Process_Globals
End Sub
Timer1.Initialize("T1", 1000)
End If
End Sub
122
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Timer Tick Event Routine
sub ကေတာ့ေအာက္ပါပံုစအ
ံ တုိင္းျဖစ္ပါတယ္။
Sub Timer1_Tick
'Do something
End Sub
3.11. File
တုိ႕ျဖစ္ပါတယ္။
File.DirAssets
Assets folder ဆိုတာ „Files‟ folder ပါဘဲ (Project create လုပ္ျပီးေနာက္ Files နဲ႕ Object folder
၀ခုကို create လုပ္ေပးပါတယ္) ဒီ ဖုိင္ေတြဟာ read only file ေတြျဖစ္ပါတယ္။ ဒါေၾကာင့္ Dir.Assets
folder ထဲမွာ database file ရွိေနရင္ database file ကုိမသံုးမီအျခား folder ထဲကို copy လုပ္ရမယ္။
123
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
File.DirInternal / File.DirInternalCache
File.DirRootExternal
File.DirDefaultExternal
SD card မွာ install လုပ္ထားတဲ့ application ေတြအတြက္ default folder ပါ။ Path
ကေတာ့
<storagecard>/Android/data/<package>/files/
File.ExternalReadable နဲ႕
ကိုသံုးရတယ္။ File ရွိရင္ True ကုိ return ျပန္ျပီးမရွိရင္ False ကုိ return ျပန္မယ္။
124
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
File.OpenOutput (Dir As String, FileName As String, Append As Boolean)
ဖတ္ဘို႕ရည္ရြယ္ခ်က္နဲ႕ဖုိင္ကိုဖြင့္ပါတယ္။
items အျဖစ္ဖတ္ပါလိမ့္မယ္။ ဆိုလိုတာက value မွာ new line character ပါခဲ့ရင္ ဖုိင္မွာေရးစဥ္က
125
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
File.WriteMap (Dir As String, FileName As String, Map As Map)
File ကိုဖတ္ျပီး ရလာတဲ့ key/value ေတြကို Map object အျဖစ္ return ျပန္ပါတယ္။ Return
နဲ႕တူခ်င္မွတူပါမယ္။
String)
ဥပမာ DirRootExternal ထဲက file ေတြနဲ႕ subdirectory name ေတြကို List1 ထဲထည့္ရန္…
List1 = File.ListFiles(File.DirRootExternal)
File ရဲ႕ size ကုိ byte နဲ႕ျပေပးပါတယ္။ Assets folder ထဲကဖိုင္အတြက္ေတာ့ ဒီ method
သံုးလို႕မရပါဘူး။
126
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.11.2. File Name
a to z, A to Z, 0 to 9
dot (.)
underscore (_)
+-%&
Spaces နဲ႕ * ?
myfile.txt နဲ႕မတူပါဘူး။
3.11.3. Subfolder
ေအာက္ပါအတုိင္းလုပ္ရပါတယ္။
File.MakeDir(File.DirInternal, "Pictures")
သို႕မဟုတ္ subfolder name နဲ႕ file name ၾကားမွာ „/‟ ထည့္ေပးရမယ္။ ဥပမာ
127
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.12. TextReader/TextWriter
File ေတြ read/write လုပ္ဘို႕ File object မသံုးဘဲ TextReader နဲ႕ TextWriter object
TextReader/TextWriter ကပိုအဆင္ေျပပါတယ္။
3.12.1. TextWriter
ျဖစ္ပါတယ္။
Initialize
ဥပမာ
128
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Initialize2
ဥပမာ
8859-1")
Text ကိo
ု utput stream မွာေရးပါတယ္။
List ထဲက item တစ္ခုကို တစ္လုိင္းႏႈန္းနဲ႕ output stream မွာ ေရးပါတယ္။ List ထဲက
Close
Writer.Close
129
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.12.2. TextReader
(ဖုိင)္ ျဖစ္ပါတယ္။
Initialize
ဥပမာ
Reader.Initialize(File.OpenInput(File.DirRootExternal, "Test.txt"))
Initialize2
ဥပမာ
ReadAll As String
txt = Reader.ReadAll
130
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ReadLine As String
ျပန္ပါတယ္။ ဥပမာ
Reader.Initialize(File.OpenInput(File.DirDefaultExternal, "Text.txt")
line = Reader.ReadLine
Log(line)
line = Reader.ReadLine
Loop
Reader.Close
ReadList As List
Input stream မွာရွိတဲ့ text ေတြကိုဖတ္ျပီး list ထဲကိုထည့္ပါတယ္။ အားလံုးျပီးရင္ list ကုိ
List1 = Reader.ReadList
Close
TextReader.Close
131
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
page လို႕လည္းေခၚၾကပါေသးတယ္။ Android ရဲ႕ default character set ကေတာ့ Unicode UTF-8
ျဖစ္ပါတယ္။ Windows မွာ အသံုးမ်ားတဲ့ character sets ေတြကေတာ့ ASCII နဲ႕ ANSI ပါ။
အစရွိသည္တို႕ျဖစ္ပါတယ္။
Windows program ေတြက generate လုပ္တဲ့ file ေတြကို ANSI character-set နဲ႕
encode လုပ္ပါတယ္။ ဥပမာ Excel file နဲ႕ Notepad file ေတြကို ANSI character-set နဲ႕ encode
လုပ္ပါတယ္။ ဒါေပမယ့္ Notepad file ေတြကို UTF-8 encoding နဲ႕ေျပာင္း save လို႕ရပါတယ္။
UTF -16
UTF - 16 BE
UTF - LE
Windows-1252
132
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ANSI နဲ႕ encode လုပ္ထားတဲ့ Windows file ေတြကိုဖတ္ဘို႕ဆိုရင္ Windows-1252
character-set ကိုသံုးရမယ္။
ကိထ
ု ပ္ထည့္ေပးရမယ္။
Excel file တစ္ခုကို text editor တစ္ခုခု ဥပမာ (NotePad or Notepad++) နဲ႕ဖြငပ
့္ ါ။
သို႕မဟုတ္ ေအာက္ပါနည္းလမ္းအတုိင္းေဆာင္ရြက္ပါ။
ကိုသံုးပါ။
လုပ္ပါ။
133
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
နမူနာ code segment ကိုေအာက္မွာျပထားပါတယ္။
Dim tr As TextReader
txt = tr.ReadAll
tr.Close
Dim tw As TextWriter
tw.Write(txt)
tw.Close
File တစ္ခုကို NotePad နဲ႕ save လုပ္ရင္ byte ၁ခုထပ္ထည့္ပါတယ္။ အဲဒီ byte ေတြကို
BOM (Byte Order Mark)character လို႕ေခၚပါတယ္။ UTF-8 enconding မွာ ဒီ byte sequence
ေျပာင္းဘို႕ေအာက္ပါနည္းလမ္းနဲ႕ေဆာင္ရြက္ႏုိင္ပါတယ္။
var = "Gestió"
arrByte = var.GetBytes("Windows-1252")
134
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.14. List
မဆိုသိမ္းႏုိင္ပါတယ္။ ဒါေပမယ့္ List ကုိ Process Global object အျဖစ္ declare လုပ္ထားရင္ေတာ့
သြားမွာျဖစ္ပါတယ္။
Initialize
List1.Initialize
Initialize2
List ကုိ value ေတြနဲ႕ initialize လုပ္ဘုိ႕ Initialize2 method ကိုသံုးပါ။ Array ကေန list
ဥပမာ ဿ
ဥပမာ ၀
135
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
SomeArray = Array As String (“Android”,”iOS”,”Windows”,”DOS”,”UNIX”)
List1.Initialize2(SomeArray)
List1.Add(Value)
ကုိသံုးပါ။
ဥပမာ
ေတြထည့္တယ္။
List1.AddAll(12, List2) ဆိုရင္ List1 ရဲ႕ index 12 ကစျပီး List2 ရဲ႕ item
ေတြကိုထည့္မယ္။
List1.AddAllAt(12, Array As Int(1, 2, 3, 4, 5)) ဆိုရင္ List1 ရဲ႕ index 12 ကစျပီး Array
136
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
InsertAt (Index As Int, Item As Object)
List1.InsertAt(12, Value)
List1 ရဲ႕ position 12 မွာ Value ကိုထည့္မယ္။ ဒါဆိုရင္ မူလ position 12 မွာရွိေနတဲ့ item
ကိုေရႊ႕သြားမယ္။ ဒီလိုနဲ႕တစ္ခုစီေနာက္ကိုေရႊ႕သြားပါလိမ့္မယ္။
ဥပမာ
List1.RemoveAt(12)
Size
List1.Size
Get(Index As Int)
137
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဥပမာ
number = List1.Get(12)
ဥပမာ
For i = 0 To List1.Size - 1
number = List1.Get(i)
Log(number)
Next
အထက္ပါ code ကုိ run ရင္ Logs area မွာ List1 ထဲရွိသမွ် object ေတြကိုျပပါလိမ့္မယ္။
အထက္ပါ code ဟာ List1 ရဲ႕ item ေတြကို SD card ထဲက Test.txt file မွာေရးပါတယ္။
ဖိုင္ကဖ
ို တ္ျပီး List ထဲထည့္လို႕လည္းရပါတယ္။
138
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Set (Index As Int, Item As Object)
ဥပမာ
List1.Set(12, Value)
နဲ႕အစားထုိးပါတယ္။
List1.Sort(True) (ငယ္စဥ္ၾကီးလိုက္စီမယ္)
List1.Sort(False) (ၾကီးစဥ္ငယ္လိုက္စီမယ္)
SortCaseInsensitive(Ascending As Boolean)
ယူဆမယ္။ ဥပမာ
List1.SortCaseInsensitive(True) (ငယ္စဥ္ၾကီးလိုက္စီမယ္)
List1.SortCaseInsensitive(False) (ၾကီးစဥ္ငယ္လိုက္စီမယ္)
List1.Clear
139
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.15. Map
ဘဲက်န္ပါလိမ့္မယ္။
တစ္ခုျဖစ္ႏုိင္တယ္။ Map ေတြဟာ List နဲ႕ဆင္တူပါတယ္။ Map ကုိ process global variable အျဖစ္
Initialize
Map1.Initialize
Map1.Put("Language", "English")
entry တစ္ခုျဖစ္ပါတယ္။
Get(Key As Object)
Language = Map1.Get("Language")
140
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
GetKeyAt(Index As Int)
Key = Map1.GetKeyAt(12)
GetValueAt(Index As Int)
Value = Map1.GetValueAt(12)
ContainsKey(Key As Object)
ဥပမာ Map1 ထဲမွာ Language ဆိုတဲ့ Key ရွိသလားစစ္ျပီး ရွိပါက ရွိေၾကာင္း message box
ျပရန္…
If Map1.ContainsKey("Language") Then
Return
End If
Remove(Key As Object)
141
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဥပမာ Map1 ထဲက Key = „Language‟ ျဖစ္ေသာ entry ကုိဖ်က္ရန္…
Map1.Remove("Language")
Clear
Map1.Clear
ကိုလည္းသံုးႏိုငတ
္ ယ္။
ဥပမာ
142
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 3.4
project တစ္ခုလုပ္ပါ။
End If
SaveStringExample
ReadStringExample
WriteListExample
WriteMapExample
ReadMapExample
WriteTextWriter
ReadTextReader
End Sub
SaveStringExample
ဆိုတဲ့ စာ၀ေၾကာင္းကို SD card ရဲ႕ root folder ေအာက္က String.txt file မွာေရးမယ္။ String.txt
143
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub SaveStringExample
File.WriteString(File.DirRootExternal, "String.txt", _
"This is some string" & CRLF & "and this is another one.")
End Sub
ReadStringExample
Sub ReadStringExample
End Sub
WriteListExample
List1 မွာ 1 ကေန 100 ထိထည့္မယ္။ ျပီးရင္ List1 ထဲက item ေတြကို SD card ရဲ႕ root
တစ္ေၾကာင္းႏႈန္းနဲ႕ေရးပါတယ္။
Sub WriteListExample
List1.Initialize
For i = 1 To 100
List1.Add(i)
Next
End Sub
144
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ReadListExample
List1 ရဲ႕ size, List1 ရဲ႕ position ၁ခုေျမာက္မွာရွိတဲ့ item ကုိ message box မွာျပပါတယ္။ List1 မွာ
item ရဲ႕ position က 2 ျဖစ္ပါတယ္။ (မွတ္ခ်က္ List1 ကုိ initialize လုပ္ဘို႕မလိုပါ။ List1 မွာ file
Sub ReadListExample
Msgbox("List1.Size = " & List1.Size & " Third item is:" & List1.Get(2), "")
End Sub
WriteMapExample
Brand Samsung
Price 100000
Keys Values
အထက္ပါ map မွာ entry ၁ခုရွိပါတယ္။ Entry တစ္ခုမွာ key-value တစ္စံုပါပါတယ္။ ဥပမာ
(Brand Samung) entry မွာ Brand ဟာ key ျဖစ္ျပီး Samsung ဟာ value ျဖစ္ပါတယ္။
145
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
WriteMapExample sub မွာ For-Next loop ကိသ
ု ံုးျပီး Map1 ထဲကို ေအာက္ပါ entry
ေတြထည့္ပါတယ္။
Key1 Value1
Key2 Value2
… …
… …
… …
Key100 Value100
Map1 ထဲက entry ေတြကို Map.txt file မွာေရးပါမယ္။ ေရးတဲ့အခါ entry တစ္ခုကို
တစ္လုိင္းႏႈန္းနဲ႕ေရးမွာျဖစ္ပါတယ္။
Sub WriteMapExample
Map1.Initialize
For i = 1 To 10
Next
End Sub
ReadMapExample
146
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Map1 ထဲက entry တစ္ခုရဲ႕ key ကုိဖတ္ခ်င္ရင္…
Map1.GetKeyAt(i)
Map1.GetValeAt(i)
လုိ႕ဖတ္ရပါတယ္။
Sub ReadMapExample
Dim K, V As String
K = Map1.GetKeyAt(0)
V = Map1.GetValueAt(0)
Msgbox(K,V)
End Sub
Key1 Value1
ကိုေတြ႕ရမယ္။
147
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၁-၃
WriteTextWriter
TextWriter object သံုးျပီး string ေတြကို ဖုိင္တစ္ခုမွာ ေရးပါမယ္။ TextWriter1 object ကုိ
ဒီ method မွာ write လုပ္မယ့္ဖုိင္ရဲ႕ folder name, file name, append လုပ္မယ္/မလုပ္ဘူး
(True/False) ေပးရမယ္။ ျပီးရင္ ဒီ output stream ကုိသံုးျပီး TextWriter1 ကုိ initialize လုပ္ရမယ္။
For-Next loop ကုိသံုးျပီး Text.txt file မွာ Line1 ကေန Line10 ထိ တစ္လို္င္းစီေရးပါမယ္။ ဥပမာ
Line1
Lint2
Line10
Sub WriteTextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal,"Text.txt", False))
148
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
For i = 1 To 10
TextWriter1.WriteLine("Line" & i)
Next
TextWriter1.Close
End Sub
ReadTextReader
Sub ReadTextReader
TextReader1.Initialize(File.OpenInput(File.DirRootExternal, "Text.txt"))
line = TextReader1.ReadLine
Log(line)
line = TextReader1.ReadLine
Loop
149
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
TextReader1.Close
End Sub
Reaular Expression ဆိုတာ string တစ္ခုမွာ eMail address ပါသလား၊ user input date
method ေတြကို သံုးဘို႕အတြက္ Regex object ကို သံုးရမယ္။ Regular expression method
IsMatch2 တုိ႕ျဖစ္ပါတယ္။ String တစ္ခုလံုးဟာ pattern နဲ႕ match ျဖစ္ရင္ True ကုိ return
ျပန္မယ္။ ေအာက္ပါ code ကေတာ့ date string တစ္ခုဟာ **-**-**** ဆိုတဲ့ format
အတုိင္းျဖစ္ရဲ႕လားလို႕စစ္တာပါ။
Regex.IsMatch("\d\d-\d\d-\d\d\d\d", "11-15-2010")
၀ခု - digit ၀ခု - digit ၂ခု ပံုစံကိုက္ေနလို႕ match ျဖစ္ပါတယ္။ ဒါေၾကာင့္ True ကုိ return
ျပန္ပါမယ္။
Regex.IsMatch("\d\d-\d\d-\d\d\d\d", "11\15\2010")
150
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.16.2. Splitting Text
Split နဲ႕ Split2 method ေတြဟာ ေပးထားတဲ့ pattern ကုိသံုးျပီး string ထဲမွာပါတဲံ text
ေတြကိုခြဲထုတ္ေပးပါတယ္။ ဥပမာ
data = "123,432,13,4,12,534"
အထက္ပါ code မွာ pattern က comma ( , ) ပါ။ data ထဲက ( , ) နဲ႕ျခားထားတဲ့ text
ေတြကိုခြဲထုတ္ပါတယ္။ ခြဲလို႕ရတဲတ
့ စ္ခုခ်င္းကို „numbers‟ array ထဲထည့္ပါတယ္။
numbers(2) မွာ 13
numbers(3) မွာ 4
numbers(4) မွာ 12
numbers ထဲက text ေတြကို List l ထဲထည့္ပါ။ l ထဲက text ေတြကို Logs area
မွာထုတ္ၾကည့္ပါ။
Dim l As List
l.Initialize2(numbers)
Log(l)
151
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ေတြ႕မယ္)
ေအာက္ပါအတုိင္းလည္းသံုးႏိုင္တယ္။
ကေအာက္ပါပံုစံမ်ိဳးျဖစ္ပါတယ္။
***@***.***
Log(matcher1.Match)
Loop
mike@gmail.com
john@gmail.com
152
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
User input date တစ္ခုဟာ ကိုယ္လိုခ်င္တဲ့ format အတုိင္းျဖစ္ရဲ႕လား၊ ျဖစ္ခဲ့ရင္လည္း
စစ္ေဆးႏုိင္ပါတယ္။
SubActivity_Create(FirstTime As Boolean)
End Sub
months = matcher1.Group(1)
days = matcher1.Group(2)
Return True
Else
Return False
End If
End Sub
153
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
3.17. Intent
Application တစ္ခုကေန အျခား application ရဲ႕ Activity ကုိေခၚခ်င္ရင္ Intent object ကုိ
create လုပ္ရမယ္။ Intent object မွာ Action နဲ႕ Uri ေပးျပီး initialize လုပ္ပါ။ ျပီးရင္ StartActivity
method ကိုသံုးျပီးေခၚပါ။
Example 3.5
Calling Phone
Button တစ္ခုပါတဲ့ layout လုပ္ပါ။ Layout name ကုိ Layout1 လို႕ေပးပါ။ Activity_Create
Activity.LoadLayout("Layout1")
End Sub
Phone application ရဲ႕ Activity ကုိေခၚဘုိ႕ Intent object တစ္ခုကို declare လုပ္ျပီး
initialize လုပရ
္ မယ္။ Initialize method မွာ parameter ၀ခုေပးရမယ္။ ပထမ parameter က
Action ျဖစ္ပါတယ္။ i.ACTION_VIEW လို႕ေပးပါ။ ဒုတိယ parmater မွာ Uri (phone number)
Sub Button1_Click
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "tel:0973140515")
StartActivity(i)
End Sub
154
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Program ကုိ run ျပီးေနာက္ Button1 ကုိ click ရင္ device မွာပါျပီးသား phone
ပံု ၁-၄
155
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Phone number ကိုမျပဘဲ Button1 ကုိႏွိပ္လုိက္တာနဲ႕ တန္းေခၚခ်င္ရင္ Action မွာ
i.ACTION_CALL လုိ႕ေပးပါ။
Sub Button1_Click
Dim i As Intent
i.Initialize(i.ACTION_CALL, "tel:0973140515")
StartActivity(i)
End Sub
ထည့္ေပးရပါမယ္။
AddPermission(android.permission.CALL_PHONE)
ပံု ၁-၅
Example 3.6
Sending SMS
receiver ရဲ႕ phone number ကိုထည့္ပါ။ „i‟ ကုိ initialize လုပ္ပါ။ Action နဲ႕ Uri ေပးရမယ္။
ပို႕ခ်င္တဲ့ message ကို PutExtra method နဲ႕ Intent object „i‟ ထဲထည့္ပါ။ ျပီးရင္ StartActivity
156
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Button1_Click
Dim i As Intent
StartActivity(i)
End Sub
Example 3.7
Sub Button1_Click
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "http://www.facebook.com")
StartActivity(i)
End Sub
157
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 4
4.1. Process
Process မွာ UI thread လို႕ေခၚတဲ့ main thread တစ္ခု ရွိပါတယ္။ Process ရွိေနသမွ် main
thread လည္း ရွိေနမွာပါ။ Process တစ္ခုမွာ main thread အျပင္ background task
အတြကသ
္ ံုးႏုိငတ
္ ဲ့ အျခား thread ေတြလည္းရွိႏုိင္ပါတယ္။
ေနာက္တစ္ၾကိမ္ ျပန္ run တဲ့အခါ ခုနက process ကိုလည္း kill မလုပ္ရေသးဘူးဆိုရင္ အဲဒီ
4.2. Activity
Activity ဆိုတာ Windows form ပံုစံမ်ိဳးပါ။ Activity နဲ႕ Windows form မတူတာတစ္ခု
Activity ကုိ kill မလုပ္မီသူ႕ရဲ႕ state ကို save လုပ္ထားဘို႕လုိပါတယ္။ Memory မွာေသာ္
158
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Device ရဲ႕ orientation (ေထာင္လုိက/္ အလ်ားလုိက)္ ေျပာင္းသြားတဲ့အခါမ်ိဳးမွာ
Sub Process_Globals
End Sub
Sub Globals
End Sub
End Sub
Sub Activity_Resume
End Sub
End Sub
4.3. Variable
Variables ေတြမွာ global variable နဲ႕ local variable ဆိုျပီး ၀မ်ိဳးရွိပါတယ္။ Sub တစ္ခုအ
တြင္းမွာ declare လုပ္တဲ့ variable ေတြကုိ local variable လို႕ေခၚပါတယ္။ သူ႕ကို declare လုပ္
159
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
၀မ်ိဳး ရွိပါတယ္။ Process variable နဲ႕ Activity variable ပါ။
Sub Process_Globals
End Sub
Sub Process_Globals
End Sub
တယ္။ ဒီ variable ေတြဟာ public variable ေတြ ျဖစ္ပါတယ္။ ဒါေၾကာင့္ ဒီ variable ေတြကို အျခား
အျဖစ္ declare မလုပ္ႏုိင္ပါဘူး။ ဥပမာ view ေတြကို process variable အျဖစ္ declare မလုပ္ႏုိင္
destroy လုပ္လုိက္ရင္ view ေတြပါ destroy ျဖစ္သြားပါမယ္။ ဒါေၾကာင့္ Activity destroy ျဖစ္တဲ့အခါ
160
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ေနရာယူထားတဲ့အတြက္ memory မလံုေလာက္မႈကို ျဖစ္ေစႏုိင္ပါတယ္။
Sub Globals
End Sub
Sub Globals
End Sub
အတြင္းမွာသာ access လုပ္ႏုိင္ပါတယ္။ View ေတြကို Activity variable အျဖစ္ declare လုပ္ရပါ
မယ္္။ Activity ကုိ create လုပ္တုိင္းမွာ Globals sub ကို ေခၚပါတယ္။ Activity ရွိေနသမွ် Activity
4.4. Activity_Create
Activity ကုိ create လုပ္တဲ့အခ်ိန္မွာ Globals sub ကို ေခၚျပီးေနာက္ Activity_Create sub
ကုိ ေခၚပါတယ္။ Activity ကုိ ဘယ္အခ်ိန္ create လုပ္သလဲဆိုေတာ့… user က application ကုိ
ဖြငလ
့္ ုိက္တဲ့အခ်ိန္မွာ activity ကုိ create လုပ္ပါတယ္။ Device configuration change သြားတဲ့အခါ
activity ကုိ create လုပ္ပါတယ္။ ဒါေၾကာင့္ application ကုိ ဖြင့္တာနဲ႕ ေပၚလာရမယ့္ layout file ကို
161
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Activity Create sub အတြင္းမွာ load လုပ္ရပါတယ္။ ဥပမာ
Activity.LoadLayout(“Layout1”)
End Sub
4.5. FirstTime
ဆိုတာ ေဖာျ္ပဘုိ႕သံုးတာပါ။ FirstTime ရဲ႕ value ဟာ True or False ျဖစ္ပါမယ္။ Activity ကုိ
ပထမဆံုးအၾကိမ္ create လုပ္တာဆိုရင္ FirstTime ရဲ႕ value က True ျဖစ္မွာပါ။ Process variable
ဒါေၾကာင့္ process variable ေတြကို initialize လုပ္ဘုိ႕ FirstTime ရဲ႕ value ကုိ ၾကည့္ရပါတယ္္။
FirstTime ရဲ႕ value က True ျဖစ္ရင္ ဒါ Activity ကုိ ပထမဆံုးအၾကိမ္ create လုပ္တာ ျဖစ္တယ္။
If FirstTime Then
TTS1.Initialize(“TTS1”)
End If
End Sub
162
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
4.6. Activity_Resume
4.7. Activity_Pause
ေနာက္ဆံုးေနရာပါ။
save ႏုိင္ပါတယ္။
storage မွာ save လုပ္သင့္ပါတယ္။ မ save ခဲ့ရင္ ေျပာင္းထားတဲ့ setting ေတြ ေပ်ာက္သြား
မွာျဖစ္ပါတယ္။
၂မ်ိဳးေၾကာင့္ ျဖစ္ႏိုင္ပါတယ္။
163
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
သိမ္းထားမယ္။ user က လိုအပ္တဲ့အခါ ျပန္သံုးႏိုင္ေအာင္ေပါ့။
ျပီးရင္ create ျပန္လုပ္မယ္ (ေနာက္ထပ္ layout variant တစ္ခုကိုသံုးျပီး create လုပ္မွာပါ။ ဥပမာ
4.8. UserClosed
Activity ကုိ pause လုပ္တယ္။ ျပီးရင္ destroy လုပ္ပါတယ္။ Back button ကုိ ႏိွပ္တာနဲ႕ အတူတူဘဲ
ျဖစ္ပါတယ္။
ျဖတ္ႏုိင္တယ္။ UserClosed = True ျဖစ္ေနရင္ save လုပ္စရာမလိုဘူး (ျပန္ create လုပ္မွာ မဟုတ္
ေတာ့လို႕ပါ) UserClosed = False ျဖစ္ေနရင္ေတာ့ process variable ေတြကို သူ႕ရဲ႕ မူလ initial
ေခၚပါတယ္။ ဒုတိယ Activity_Resume subroutine ကို ေခၚပါတယ္။ Back key ကုိ ႏွိပ္လိုက္ရင္
164
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
Log("Create")
End Sub
Sub Activity_Resume
Log("Resume")
End Sub
Log("Pause")
End Sub
မ run ခင္ device ကို computer နဲ႕ ခ်ိတ္ပါ။ ျပီးရင္ Tool bar ေပၚက ကို click ျပီး run
ပါ။
ပံု ၂-ဿ
dialog ကုိပိတ္လုိက္ပါ။ ျပီးရင္ ပံု (၂-၀) မွာျပထားတဲ့အတုိင္း Tabs area မွာ Logs tab ကုိေရြးပါ။
165
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၂-၀
Create
Resume
ဆိုျပီးေပၚေနပါလိမ့္မယ္။
မွာ Log (“Create”) လို႕ ေရးခဲ့တယ္ေလ။ „Log‟ keyword ကေတာ့ (“”) ထဲမွာ ေရးထားတဲ့ string
ကုိ Logs area မွာ ေဖာ္ျပေပးတာပါ။ Activity_Create sub ကို ေခၚလုိက္လို႕သာ Logs area မွာ
Create ဆိုတာကိထ
ု ုတ္ျပေပးတာပါ။
cycle ပါ။ ဒီ sub ေတြထဲမွာ လုိအပ္တဲ့ code ေတြ ေရးျခင္းျဖင့္ လိုအပ္တဲ့ application ကုိ develop
လုပ္ရမွာ ျဖစ္ပါတယ္။
Pause
ကုိေခၚတယ္ဆိုတာ သိႏိုင္ပါတယ္။
ေနာက္တစ္ခါ device ေပၚမွာ ခု install လုပ္ျပီးသြားတဲ့ application ကုိ ျပန္ run ပါ။ (Device
မွာ install လုပ္ျပီးသား application ကုိ ျပန္ဖြင့္ခုိင္းတာပါ။ PC ကေန run ခုိင္းတာ မဟုတ္ပါဘူး)
166
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Logs area မွာ…
Create
Resume
ဒီတစ္ခါေတာ့ Back key မႏွိပ္ဘဲ Home key ကုိ ႏွိပ္လုိက္ပါ။ ျပီးရင္ Logs area မွာ ၾကည့္ပါ။
Pause
သိႏုိငပ
္ ါတယ္။ အခုတစ္ခါ application ကုိ ျပန္ run ပါဦး။ ျပီးရင္ Logs area မွာ ၾကည့္ပါ။
Resume
Pause
Create
Resume
Pause
Create
Resume
167
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
Log(FirstTime)
Log("Create")
End Sub
Sub Activity_Resume
Log("Resume")
End Sub
Log(UserClosed)
Log("Pause")
End Sub
area မွာ
True
Create
Resume
ဆိုျပီး ေတြ႕ပါမယ္္။ Application ကုိ စ run ရင္ FirstTime ဟာ True ျဖစ္မယ္ဆိုတာ ေတြ႕ျပီေနာ္။
„True
Pause
ဆိုျပီး ေတြ႕မယ္။ ဒါဆို Back key ႏွိပ္ရင္ UserClosed ဟာ True ျဖစ္တယ္ဆိုတာ ေတြ႕ျပီေနာ္။
Screen ေပၚက application ကို ျပန္ run ပါ (Device မွာ install လုပ္ျပီးသား application ကုိ
168
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပန္ဖြင့္ခုိင္း တာပါ။ PC ကေန run ခုိင္းတာ မဟုတ္ပါဘူး)
False
Create
Resume
ဆိုျပီး ေတြ႕မယ္ေနာ္။ ဒါကေတာ့ Activity ကုိ ပထမဆံုးအၾကိမ္ run တာမဟုတ္ဘဲ Back key ႏွိပ္ျပီး
ျပန္ run တာမုိ႕ FirstTime ဟာ False ျဖစ္ေနတာပါ။ ဒီတစ္ခါ Home key ကို ႏွိပ္လိုက္ပါဦး။
„False
Pause
ဆိုျပီး ေတြ႕မယ္ေနာ္။ ဒါကေတာ့ Home key ကုိ ႏွိပ္ရင္ UserClosed ဟာ False ျဖစ္လို႕ပါဘဲ။
အားလံုးျခံဳျပီး ျပန္ေျပာပါမယ္။
စ run ရင္
Resume
Resume
Resume
အထက္ပါ application ကို run ထားျပီး device ကုိ ေထာင္လိုက္၊ လဲွလိုက္ လုပ္ၾကည့္ပါဦး။
169
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ေထာင္လိုက္၊ လွဲလိုက္တိုင္းမွာ UserClosed က False ေတြခ်ည္း ျဖစ္ေနပါလိမ့္မယ္။ ဒါေၾကာင့္
4.10. Activity.Finish/ExitApplication
Activity ၁ခုလုပ္ပါ။
Main activity
SecondActivity
ThirdActivity
StartAcivity(SecondActivity)
StartAcivity(ThirdActivity)
ျပန္ေရာက္သြားပါလိမ့္မယ္။
ျပန္ေရာက္သြားပါမယ္။
170
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ထဲကထြက္သြားပါလိမ့္မယ္။
Activity.Finish
StartAcivity(SecondActivity)
Activity.Finish
StartAcivity(ThirdActivity)
Example 4.1
ပံုမွာျပထားတဲ့အတုိင္းသတ္မွတ္ေပးပါ။
171
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Layout Name: Layout1
ပံု ၂-၁
ပံု ၂-၂
172
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Layout: Layout3
ပံု ၂-၃
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
173
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
End Sub
Sub Button1_Click
StartActivity(SecondActivity)
Activity.Finish
End Sub
SecondActivity မွာေအာက္ပါအတုိ္င္းေရးပါ။
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
174
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout2")
End Sub
Sub Activity_Resume
End Sub
End Sub
Sub Button1_Click
StartActivity(ThirdActivity)
Activity.Finish
End Sub
ThirdActivity မွာေအာက္ပါအတုိ္င္းေရးပါ။
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
175
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout3")
End Sub
Sub Activity_Resume
End Sub
End Sub
176
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 5
Module
Activity module
Class module
Code module
Service module
Project ထဲကို module အသစ္တစ္ခု ထည့္ခ်င္ရင္ IDE menu မွာ [Project > Add New
ပံု ၃-ဿ
ရွိျပီးသား module ကို project ထဲ ထည့္ခ်င္တာဆိုရင္ေတာ့ IDE menu မွာ [Project >
ပံု ၃-၀
177
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
5.1. Activity Module
object/variable ေတြကို အျခား module ကေန access လုပ္ခ်င္ရင္ object/variable name ေရွ႕မွာ
Main module
Sub Process_Globals
End Sub
Main module ထဲမွာ declare လုပ္ထားတဲ့ Value1, Value2, Value3 တို႕ကို အျခား
Other module
Log(Main.Value2)
End Sub
Activity module တစ္ခုအတြင္းက view ေတြကို အျခား Activity ကေန access မလုပ္ႏုိင္
လုပ္လက
ို ္ပါတယ္။ Pause လုပ္ထားတဲ့ Activity ထဲက view ေတြကို အျခား Activity ကေန access
178
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
5.3. Code Module
Basic4android v1.2 ကစျပီး static code module ဆိုတဲ့ module type အသစ္တစ္ခု
ပါှင္လာပါတယ္။ Static code module ကုိ ထည့္ဘုိ႕ကေတာ့ [Project > Add New Module
>CodeModule] ကို ေရြးပါ။ ပံု (၃-၁) မွာ ျပထားတဲ့အတုိင္း dialog box ေပၚလာရင္ module name
ကုိ ရိုက္ထည့္ပါ။
ပံု ၃-၁
အသင့္ျဖစ္လာပါမယ္။
'Code module
Sub Process_Globals
'These global variables will be declared once when the application starts.
End Sub
process life cycle နဲ႕ ဆက္စပ္မႈ လံုးှမရွိပါဘူး။ Code module ဟာ code ေတြေရးထားတဲ့
179
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျဖစ္ပါတယ္။ ဒါေၾကာင့္ အျခား module ေတြကပါ access လုပ္ႏုိင္ပါတယ္။ Code module ေတြ
Code module မွာေရးျပီးသား code ေတြကို အျခား module ေတြမွာ ျပန္ေရးစရာ မလုိေတာ့
ဘဲ အသင့္ယူသံုးႏုိင္ပါတယ္။
အျခား project ေတြဟာ code ေတြကို share လုပ္ျပီး သံုးႏုိင္ပါတယ္။ (ဥပမာ XML file ကို
parse လုပ္တဲ့ Code module တစ္ခု ေရးထားရင္ အဲဒီ Code module ကုိ အျခား
module တစ္ခစ
ု သ
ီ ံုးႏုိင္ပါတယ္။ ဒါေၾကာင့္ program ကုိ ပိုမိုရွင္းလင္းေစျပီး maintain လုပ္ရ
တာလည္း လြယ္ကူေစပါတယ္။
Code module တစ္ခုကို ဘယ္ Activity အတြက္ ဘယ္ Service အတြက္ရယ္လို႕ သတ္မွတ္
ကုိသံုးျပီးေခၚရပါတယ္။
Activity တစ္ခုကေန message box dialog ကုိျပဘုိ႕အတြက္ Code module sub တစ္ခုကို
ေခၚလို႕ရပါတယ္။ ဒါေပမယ့္ အဲဒီ Code module sub ကုိ Service ကေန ေခၚလို႕ေတာ့ မရပါဘူး။
Code module ေတြဟာ event ေတြကို catch မလုပ္ႏုိင္ပါဘူး။ ဆိုလိုတာက Button1 ကုိ
click လုိက္ရင္ message box ေပၚခ်င္တယ္ဆိုပါေတာ့။ ဒီအတြက္ Button1_Click event sub မွာ
ၾကည့္ပါ။
Code Module
Dim b As Button
180
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
b.Initialize("But")
b.Text = Text
Return b
End Sub
Activity module ကေနအထက္ပါ Code module ကုိ ေခၚဘု႕ုိ ဆိုရင္ Activity_Create sub
မွာေအာက္ပါအတုိင္းေရးပါ။
200dip, 200dip)
create လုပ္ရပါမယ္။ ဒီ sub ကိုေတာ့ Activity module အတြင္းမွာ ေရးရမယ္ေနာ္။ Code module
Sub But_Click
Msgbox(“Hello World!”,”Greeting”)
End Sub
ျပီးရင္ program ကုိ run ၾကည့္ပါ။ press me ဆိုတဲ့ button တစ္ခုေတြ႕မယ္။ Button ကုိ
ေတြဟာ application နဲ႕ process life cycle ေတြမွာ အေရးပါတဲ့က႑က ပါှင္ပါတယ္။ Activity
181
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တစ္ခု invisible ျဖစ္သြားတာနဲ႕ Activity module ထဲမွာေရးထားတဲ့ code ေတြကုိ pause
လုပ္ပါတယ္။ ဒါေၾကာင့္ application invisible ျဖစ္ေနစဥ္မွာ Activity ထဲက ဘယ္ code ကုိမွ run
လုိ႕ရမွာမဟုတ္ပါဘူး။
Activity ကို screen ေပၚမွာ မျမင္ရေတာ့ေပမယ့္ task ေတြကို background မွာ ဆက္ျပီး run
ေနႏိုင္ပါတယ္။
ဥပမာ music player လိုမ်ိဳးေပါ့။ music file တစ္ခုကို play ျပီးေနာက္ အျခား application
code ေတြကို background မွာဆက္ run ေပးေနလုိ႕ပါ။ Background မွာ run မယ့္ code ေတြကုိ
Status bar notification ကိုသံုးျပီး interact လုပ္ႏိုင္ပါတယ္။ Service ေတြမွာ visible element ေတြ
မရွိပါဘူး။ Service ေတြဟာ dialog ေတြကိုလည္း မျပႏုိင္ပါဘူး။ Message box dialog ကုိ
မျပႏုိင္ဘူး။ ဒါေပမယ့္ Toast message ေတာ့ျပႏုိင္တယ္။ ဒါေၾကာင့္ Service code ထဲမွာ error
တစ္ခုခုျဖစ္ခဲ့ရင္ "Do you want to continue?" dialog မ်ိဳးကို ျမင္ရမွာမဟုတ္ဘူး။ Dialog အစား
ျပီးေတာ့ user က screen ကုိ rotate လုပ္လိုက္တာေၾကာင့္ Service ကို destroy လုပ္တာ
မ်ိဳးလည္း မရွိပါဘူး။ Activity ကိုေတာ့ screen rotate လုပ္တုိင္း destroy လုပ္ပါတယ္။ Service
182
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
module ထဲက code ေတြဟာ အျခား module ထဲက code ေတြလိုဘဲ same process, same
လုပ္ပစ္ပါတယ္။
Foreground
Background
o Process ထဲက Activity တစ္ခုမွ visible ျဖစ္မေနဘူး။ ဒါေပမယ့္ Service ေတာ့ run
ေနတဲ့အေျခအေန
Paused
လိုတဲ့အခါ paused process ေတြကို အရင္ဆံုး kill လုပ္ပါတယ္။ ဒါနဲ႕မွ low memory ျဖစ္ေနတံုး
ဘုိ႕လိုပါတယ္။
Service module ထည့္ဘုိ႕ကေတာ့ [Project ->Add New Module -> Service] ကို
ေရြးပါ။ Service module တစ္ခု ထည့္လုိက္ရင္ ေအာက္ပါအတိုင္း code မ်ားေရးရန္ template တစ္ခု
အသင့္ ျဖစ္ေနပါမယ္။
183
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
End Sub
Sub Service_Create
End Sub
End Sub
Sub Service_Destroy
End Sub
Service ဟာ Activity object ေတြကို support မလုပ္တဲ့အတြက္ Globals sub ေတာ့ မပါပါဘူး။ Sub
Process_Globals ကို variable ေတြ declare လုပ္ဘုိ႕သာ သံုးသင့္ပါတယ္။ အျခား code ေတြကို
မေရးသင့္ပါဘူး။ Process global variable ေတြဟာ process run ေနသမွ် တည္ရွိေနျပီး အျခား
Service ကို ပထမဆံုး start လုပ္တဲ့အခါမွာ Sub Service_Create ကို ေခၚပါတယ္။ ဒီ sub
ထဲမွာ process global variable ေတြကို initialize လုပ္ရပါတယ္။ Service တစ္ခု စတင္ျပီးတဲ့ေနာက္
184
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
StartService (or StartServiceAt) ကို ေခၚတုိင္းမွာ Sub Service_Start ကို ေခၚပါတယ္။
Sub Service_Start ကို ေခၚတဲ့အခ်ိန္မွာ process ကုိ foreground state ကုိ ေရႊ႕လိုက္ပါတယ္။
ဆုိလိုတာက ဒီ sub ကုိ run လို႕မျပီးမခ်င္း Android operating system ဟာ process ကုိ kill မလုပ္
ေခၚျပီးေနာက္မွာ service ကုိ run မွာ မဟုတ္ေတာ့ပါဘူး။ Service ကုိ destroy လုပ္လိုက္ျပီျဖစ္ပါ
တယ္။
o UI code နဲ႕ logic code ကုိ သီးျခားစီခြဲထားပါတယ္။ Service ထဲမွာ non-UI code ကို
ေတာ့ Service ကို pause လုပ္ျခင္း၊ resume လုပ္ျခင္း၊ recreate လုပ္ရျခင္းေတြ မရွိလို႕ပါ။
foreground ကေနျပန္ခ်ေပးရမယ္ေနာ္။
185
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
o ထပ္တစ္လဲလဲလုပ္ရမယ့္ task ေတြအတြက္ Service ကုိ သံုးႏိင
ု ္တယ္။ StartServiceAt
Notification
ျပပါႏုိင္ပါတယ္။ User က status bar ကုိ ဆြဲခ်လိုက္ရင္ notification message ကို ျမင္ရပါလိမ့္မယ္။
ပံု ၃-၂
User က notification message ကုိ click လုပ္လုိက္ရင္ notification object မွာ configure
186
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Accessing other Modules
Process global object ေတြဟာ public ျဖစ္တာေၾကာင့္ အျခား module ေတြကေန access
လုပ္ႏုိင္ပါတယ္။ အျခား module ထဲက sub ေတြကို ေခၚခ်င္ရင္ CallSub method ကုိ သံုးႏုိင္ပါတယ္။
ဒါေပမယ့္ Activity တစ္ခုဟာ running service ကို access လုပ္ႏုိင္ျပီး service ကလည္း
ျပန္လာမွာ ျဖစ္ပါတယ္။
သံုးႏုိင္ပါတယ္။ ဥပမာ Service တစ္ခုဟာ new data အခ်ိဳ႕ကုိ download ဆြဲထားတယ္ ဆုိပါစို႕။
CallSub(Main, "RefreshData")
new data ေတြကိုရယူႏုိင္ပါတယ္။ တစ္ခုမွတ္ထားရမွာက Code module ရဲ႕ sub ေတြကို access
187
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
Chapter 6
Resolution: Screen ရဲ႕ width နဲ႕ height ကုိ pixel အေရအတြက္နဲ႕ ေဖာ္ျပျခင္း
ဆိုရင္ တစ္လက္မမွာ 160 pixels ရွိပါတယ္။ dpi က dots per inch ပါ။ pixels per inch
188
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
6.1. Working with different Screen Sizes
အမ်ိဳးမ်ိဳး သံုးႏုိင္ပါတယ္။
6.1.2. %x and %y
View တစ္ခုရဲ႕ width ကုိ %x နဲ႕ သတ္မွတ္ျပီး height ကုိ %y နဲ႕ သတ္မွတ္ႏုိင္ပါတယ္။
Button1.Width = 50%x
ဆိုတာဟာ Button1 ရဲ႕ width ကို Activity width ရဲ႕ 50% လို႕သတ္မွတ္တာပါ။ Activity
Button1.Height = 20%y
ဆိုတာဟာ Button1 ရဲ႕ height ကို Panel height ရဲ႕ 20% လို႕သတ္မွတ္တာပါ။ Panel
dip unit ကို သံုးျခင္းျဖင့္ device ရဲ႕ scale ေပၚမူတည္ျပီး dimension ကုိ တြက္ေပးပါတယ္။
dip unit ကုိ သံုးရင္ view ရဲ႕ (physical position နဲ႕ size) ဟာ ဘယ္ device မွာမဆို အတူတူဘဲ
ျဖစ္ေနမွာပါ။ ဥပမာ Button1 ရဲ႕ width ကို 160dip လို႕သတ္မွတ္လိုက္ရင္ (resolution = 320
/480, scale = 1 device မွာ) 1” က်ယ္မွာျဖစ္ျပီး၊ (resolution = 480 / 720, scale = 1.5 device
189
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
တြက္နည္းကေတာ့…
Example 6.1
Project တစ္ခု create လုပ္ျပီး Globals နဲ႕ Activity_Create sub တို႕မွာ ေအာက္ပါအတုိင္း
Sub Globals
End Sub
Button1.Initialize("Button1")
End Sub
190
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
Activity
30 %y
Button1 100dip
200dip
20 %x
ပံု ၆-၁
Text size ကုိေတာ့ physical unit နဲ႕ တုိင္းတာျပီးသားျဖစ္တာမုိ႕ dip unit ကုိ မသံုးရပါဘူး။
Portrait only
Landscape only
Both
191
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
Orientation သတ္မွတ္ႏိုင္တဲ့ေနရာေတြကေတာ့…
#ApplicationLabel: MyFirstProgram
#VersionCode: 1
#VersionName:
#CanInstallToExternalStorage: False
#End Region
Landscape အတြက္
SetScreenOrientation(0)
Portrait အတြက္
SetScreenOrientation(1)
၂မ်ိဳးလံုးအတြက္
SetScreenOrientation(-1)
192
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (၁)
Example 6.2
Project တစ္ခု create လုပ္ပါ။ Libs tab ကေန Phone library ကုိ check လုပ္ပါ။ Globals
SetScreenOrientation value ကုိ 0 ထားျပီး run ပါ။ ေနာက္တစ္ခါ 1 ထားျပီး run ပါ။ Run
Sub Globals
Dim p1 As Phone
End Sub
Button1.Initialize("Button1")
p1.SetScreenOrientation(-1)
End Sub
193
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 7
Designer
Designer ကိသ
ု ံုးျပီး ျပဳလုပ္ျခင္းျဖစ္ပါတယ္၉ ဒုတိယ တစ္ခုကေတာ့ program code ေရးျပီး
ျပဳလုပ္ျခင္းျဖစ္ပါတယ္၉
IDE window မွာ Desinger menu ကုိေရြးလုိက္ရင္ (ပံု ၅-ဿ) မွာျမင္ရတဲ့အတုိင္း Designer
နဲ႕ Abstract Designer window ၀ခုပြင့္လာပါမယ္၉ User interface layout ေတြကို Abstract
ပံု ၅-ဿ
194
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.1. Menu
ပံု ၅-၀
New
Layout အသစ္တစ္ခုျပဳလုပ္ရန္၉
Open
ထဲထည့္ရန္အတြက္လည္း သံုးႏုိင္ပါတယ္၉
Save
Save As
Remove Layout
195
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.1.2. Edit Menu
ပံု ၅-၁
ပံု ၅-၂
196
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
User interface layout တစ္ခုျဖစ္လာဘုိ႕ Activity ေပၚမွာ view ေတြကို
Activity
၁ခုရွိပါတယ္၉
Sub Activity_Create
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause
End Sub
method ကုိသံုးရမယ္၉
197
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
View = Activity ထဲထည့္မယ့္ view ျဖစ္ပါတယ္၉
Top
Left Width
View
Width Height
Activity
ပံု ၅-၃
ဥပမာ Width = 75, Height = 50 ရွိတဲ့ „btnOk‟ button ကုိ Activity ရဲ႕ Left = 10,
Activity.RemoveViewAt (index)
Activity.RemoveViewAt (0)
198
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဥပမာ Layout1.bal file ကုိ Activity ထဲထည့္ရန္
Activity.LoadLayout (“Layout1”)
End Sub
လက္က Activity ရဲ႕ Left = 10, Top = 30 ကိုထိေနရင္ X = 10, Y = 30 ျဖစ္ပါမယ္၉ User
ရရွိမွာျဖစ္ပါတယ္၉
ဥပမာ
Activity.AddMenuItem (“Save”,”mnuSave”)
Activity.AddMenuItem (“Settings”,”mnuSettings”)
199
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Menu button ကုိႏွိပ္ရင္ (ပံု ၅-၄) မွာကဲ့သုိ႕ menu item ၀ခုကိုေတြ႕ရမယ္၉
ပံု ၅-၄
AutoCompleteEditText
Example 7.1
Globals
Sub Globals
End Sub
Activity_Create
200
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
auto1.Initialize ("")
String Array „nomi‟ ကို declare လုပ္ျပီး nomi ထဲကို "angela", "andrea", "angelo",
"alberto", "carlo", "Clotilde", "filippo", "giorgio", "Lyndon" အစရွိတဲ့ String item မ်ားထည့္ပါ၉
auto1.SetItems (nomi)
auto1.Initialize ("")
auto1.SetItems (nomi)
End Sub
201
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၅
Button
CheckBox
202
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
EditText
EditText1.SingleLine = False
HorizontalScrollView
scroll လုပ္ျပီး အဲဒီ view ေတြကို ၾကည့္ႏုိင္ပါတယ္၉ HorizontalScrollView မွာ inner panel
ImageView
မွာေနရာယူပါမယ္၉
203
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Label
ListView
Item ေတြ အမ်ားအျပားကို ထည့္ဘို႕ ListView ကုိ သံုးႏုိင္ပါတယ္၉ ListView မွာ event ၀ခု
ရွိပါတယ္၉ Item တစ္ခုကို click ရင္ ItemClick event ျဖစ္ေပၚျပီး item ကုိ ၾကာၾကာဖိထားရင္ေတာ့
Example 7.2
code နဲ႕လုပ္ျပပါမယ္၉
Globals
Sub Globals
End Sub
204
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Activity_Create
ListView1.Initialize ("lv1")
For Next loop သံုးျပီး ListView1 ထဲကို item အခု 300 ထည့္ပါ၉ ဥပမာ Item #1, Item
For i = 1 To 300
Next
ListView1_ItemClick
(lv1) နဲ႕ Click event ျဖစ္ေပၚပါလိမ့္မယ္၉ Event sub မွာ Position နဲ႕ Value parameter ၀ခု
ကိရ
ု ရွိပါမယ္၉ Position မွာ (click လိုက္တဲ့ item ရဲ႕ position) ပါရွိျပီး Value မွာေတာ့ (click လုိက္တဲ့
item ရဲ႕ value) ပါရွိပါမယ္၉ ဥပမာ Item #25 ကုိ click ရင္ (Position = 24) ျဖစ္ျပီး (Value = Item
#25) ျဖစ္ပါမယ္၉
Activity ရဲ႕ title မွာ Value ကုိ set လုပ္ပါ၉ Item #25 ကုိ click ရင္ Activity ရဲ႕ title မွာ
Activity.Title = Value
End Sub
205
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၆
SingleLineLayout
TwoLinesLayout
TwoLinesAndBitmap
၁မ်ိဳးလံုးကို နမူနာျပပါမယ္၉
Example 7.3
Button.gif file ကုိ Files tab (File manager) ကေန ထည့္ေပးပါ၉ Globals sub မွာ Bitmap
Activity_Create sub မွာ Bitmap1 ကုိ initialize လုပ္ပါ၉ Initialize method မွာ
206
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
parameter ၀ခု ရွိပါတယ္၉ ပထမတစ္ခုက image file ရွိရာ folder ျဖစ္ျပီး ေနာက္တစ္ခုကေတာ့
For i = 1 To 300
Bitmap1)
Next
ပံု ၅-၇
ကိုထည့္မွာျဖစ္လုိ႕ ListView1 ထဲမွာ စုစုေပါင္း item 900 ျဖစ္သြားပါမယ္၉ ဒီ example မွာ item
သတ္မွတ္ခ်င္လည္း သတ္မွတ္လို႕ရပါတယ္၉
207
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Customizing Each Type
ျပင္ဆင္သံုးႏုိင္ပါတယ္၉
Example 7.4
ListView1.SingleLineLayout.ItemHeight = 100dip
ListView1.SingleLineLayout.Label.TextSize = 20
ListView1.SingleLineLayout.Label.TextColor = Colors.Blue
ListView1.SingleLineLayout.Label.Gravity = Gravity.CENTER
208
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-ဿှ
Return Value
ItemClick event ျဖစ္ေပၚတဲ့အခါ click ခံရေသာ item ရဲ႕ value ကုိ parameter အျဖစ္ pass
လုပ္ပါတယ္၉ Item ရဲ႕ value ဆိုတာက first line မွာ ထားတဲ့ String ကုိေျပာတာပါ၉ ဒါေပမယ့္
AddSingleLine2
AddTwoLines2
AddTwoLinesAndBitmap2
ဥပမာ
Bitmap1, 1)
209
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဒီ method ေတြမွာ ေနာက္ထပ္ parameter တစ္ခုအပိုပါ ပါတယ္၉ အဲဒါကေတာ့ return
value ပါ၉ Item တစ္ခုကို click လုိက္ရင္ return ျပန္ေစခ်င္တဲ့ value ကုိေပးထားလုိ႕ရပါတယ္၉
အထက္ပါ code မွာ return value ကို 1 လို႕ေပးထားတဲ့အတြက္ item ကို click ရင္ event sub မွာ
Value = 1 ျဖစ္ပါမယ္၉
Background Optimization
Dim GD As GradientDrawable
TR = Top Right , BL = Bottom Left ျဖစ္ပါတယ္၉ ဒုတိယ parameter ကေတာ့ အေရာင္ ၀မ်ိဳး
Activity.Background = GD
Tips
210
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ListView1.TwoLinesAndBitmap.SecondLabel.Visible = False
ဥပမာ
ListView1.FastScrollEnabled = true
Complete Code
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
211
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim GD As GradientDrawable
End Sub
ListView1.Initialize ("lv1")
ListView1.SingleLineLayout.ItemHeight = 100dip
ListView1.SingleLineLayout.Label.TextSize = 20
ListView1.SingleLineLayout.Label.TextColor = Colors.Blue
ListView1.SingleLineLayout.Label.Gravity = Gravity.CENTER
Activity.Background = GD
For i = 1 To 300
line.", Bitmap1)
„ ListView1.TwoLinesAndBitmap.SecondLabel.Visible = False
Next
End Sub
212
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Resume
End Sub
End Sub
Activity.Title = Value
End Sub
Panel
Panel1.LoadLayout (“Layout1”)
ProgressBar
213
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
RadioButton
ျဖစ္သြားပါမယ္၉
ScrollView
ScrollView မွာ inner panel တစ္ခုရွိျပီး inner panel ေပၚမွာ အျခား view
Example 7.5
Layout file တစ္ခု create လုပ္ပါ၉ Layout file name ကုိ Layout1 လို႕ေပးပါ၉ Layout မွာ
code နဲ႕ create လုပ္ျပီး ScrollView ေပၚတင္ျပမွာပါ၉ Activity မွာ Label ဿ၄ ခုလံုး
ေပၚမွာ Label view ဿ၄ ခုတင္ရပါမယ္၉ ျပီးရင္ ScrollView ကုိ scroll လုပ္ျပီး Label ေတြကို
214
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Globals
End Sub
Activity.LoadLayout ("Layout1")
Dim j As Int
j=0
For i = 1 To 16
lblLabel.Initialize ("")
lblLabel.Text = "Label"& i
j = lblLabel.Top + lblLabel.Height
Next
ScrollView1.Panel.Height = lblLabel.Height * 16
End Sub
Example 7.6
SD card ထဲမွာ „Images‟ folder တစ္ခုျပဳလုပ္ျပီး image file မ်ားထည့္ထားပါ၉ အဲဒီ image
215
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Layout Name: 1
ပံု ၅-ဿဿ
216
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-ဿ၀
ပံု ၅-ဿ၁
ပံု ၅-ဿ၂
217
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Process_Globals
Sub Process_Globals
End Sub
Globals
Sub Globals
End Sub
Activity_Create
ProgressDialog တစ္ခုျပပါ၉
SD card ထဲကပံုေတြကို load လုပ္ရန္ LoadImages sub ကုိေခၚပါ၉ „Bitmaps‟ List ထဲမွာ
LoadImages
218
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Load လုပ္ျပီးရင္ progress dialog ကုိ hide ျပန္လုပ္ပါ၉
ProgressDialogHide
Activity.LoadLayout ("1")
height ကိုသတ္မွတ္ပါ၉ Image တစ္ခုစီရဲ႕ height ကို 200dip ထားပါမယ္၉ ဒါေၾကာင့္ inner panel
အားလံုးအတြက္ လုပ္ရမွာမုိ႕ For loop သံုးပါမယ္၉ For loop ကုိ i = 0 ကေန Bitmaps.Size – 1
For i = 0 To Bitmaps.Size - 1
Dim iv As ImageView
iv.Initialize ("")
„bd‟ ကို declare လုပ္ပါ၉ „bd‟ ကုိ initialize လုပ္တဲ့အခါ Bitmaps ထဲက image တစ္ခုကိုယူျပီး
သတ္မွတ္ေပးလုိက္ပါ၉
219
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim bd As BitmapDrawable
bd.Initialize (Bitmaps.Get(i))
iv.Background = bd
10dip, 190dip)
btnUp နဲ႕ btnDown ေတြရဲ႕ Tag ကို -200dip နဲ႕ 200dip အသီးသီး သတ္မွတ္ထားပါ၉
btnUp.Tag = -200dip
btnDown.Tag = 200dip
LoadImages
initialize လုပ္ပါ၉
Bitmaps.Initialize
SD card ေပၚက image folder name ကုိထည့္ရန္ „imagesFolder‟ String ကို declare
လုပ္ပါ၉
220
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ImagesFolder ထဲမွာ SD card ေပၚက image file မ်ားထည့္ထားတဲ့ folder name
အဆိုပါ folder name ရွိမရွိစစ္ပါ၉ မရွိရင္ "Images folder not found: " ဆိုတဲ့ toast
message ျပျပီးထြက္ပါ၉
ToastMessageShow ("Images folder not found: " & CRLF & imagesFolder,
True)
Return
End If
files = File.ListFiles(imagesFolder)
For i = 0 To files.Size - 1
DoEvents
f = files.Get (i)
221
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
f ထဲမွာ image file name တစ္ခုေရာက္လာပါမယ္၉ f ကို lower case ေျပာင္းျပီး .jpg
နဲ႕ဆံုးသလားစစ္ပါ၉
Dim b As Bitmap
ကိုသံုးျခင္းျဖစ္ပါတယ္၉ InitializeSample method မွာ image folder name, image file name,
နိမ့္သြားမွာပါ၉
Bitmaps.Add (b)
နဲ႕ျပပါမယ္၉
222
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
btn_Click
btnUp/btnDown button ၀ခုလံုးရဲ႕ event name ကုိ btn လုိ႕ေပးခဲ့တဲ့အတြက္ btnUp ကုိ
click သည္ျဖစ္ေစ btnDown ကုိ click သည္ျဖစ္ေစ btn Click event ျဖစ္ေပၚပါမယ္၉ Click
လုပခ
္ ံရတဲ့ button ရဲ႕ reference ဟာ Sender ထဲမွာရွိေနမွာပါ၉ ဒါေၾကာင့္ Sender ကုိ View „ v ‟
ထဲထည့္ပါ၉ ဒါဟာ Object type ကေန View type အျဖစ္ cast လုပ္လုိက္တာျဖစ္ပါတယ္၉
Dim v As View
v = Sender
ရင္ v.Tag = -200dip ျဖစ္ပါမယ္၉ btnDown ကုိ click ရင္ v.Tag = 200dip ျဖစ္ပါမယ္၉
အျဖစ္သတ္မွတ္ေပးလုိက္ပါ၉
btnUp ကုိ click တာဆိုရင္ လက္ရွိ position ထဲက -200dip ႏႈတ္တာမုိ႕ ScrollPosition ဟာ
btnDown ကုိ click တာဆိုရင္ လက္ရွိ position ကို 200dip ေပါင္းတာမုိ႕ ScrollPosition
ျမင္လာရမွာျဖစ္ပါတယ္၉
Complete Code
#FullScreen: False
#IncludeTitle: True
223
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
#ApplicationLabel: ScrollView
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
End Sub
If FirstTime Then
ProgressDialogShow("Loading images")
LoadImages
ProgressDialogHide
End If
Activity.LoadLayout ("1")
224
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
For i = 0 To Bitmaps.Size - 1
Dim iv As ImageView
iv.Initialize ("")
Dim bd As BitmapDrawable
iv.Background = bd
Next
btnUp.Tag = -200dip
btnDown.Tag = 200dip
End Sub
Sub LoadImages
Bitmaps.Initialize
ToastMessageShow ("Images folder not found: " & CRLF & imagesFolder,
True)
Return
End If
files = File.ListFiles(imagesFolder)
For i = 0 To files.Size - 1
225
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
DoEvents
Dim f As String
f = files.Get (i)
Dim b As Bitmap
Bitmaps.Add (b)
End If
Next
End Sub
Sub btn_Click
Dim v As View
v = Sender
End Sub
Sub Activity_Resume
End Sub
End Sub
226
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-ဿ၃
SeekBar
change တာလား program code နဲ႕ value change တာလား ဆိုတာကို ခြဲျခားဘုိ႕ UserChanged
parameter ကုိၾကည့္ရမယ္၉ UserChanged = True ျဖစ္ရင္ user က value ကုိ change တာျဖစ္ျပီး
Spinner
လိုက္မွသာ ထည့္ထားတဲ့ item ေတြကိုျပမယ့္ view ျဖစ္ပါတယ္၉ အဲဒီ item ေတြထဲက တစ္ခုကို user
227
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
TabHost
Example 7.7
layout file ၂ခုလုပ္ထားပါ၉ Main, P1, P2, P3 လို႕အမည္ေပးထားပါ၉ Main မွာ TabHost view
Sub Globals
End Sub
Activity_Create sub မွာ Main layout file ကုိ Activity ေပၚတင္ပါ၉ „AddTab‟ method
ကုိသံုးျပီး „tbhPages‟ ထဲကို tab ေတြထည့္ပါ၉ AddTab method မွာ parameter ၀ခု ေပးရပါတယ္၉
တစ္ခုကေတာ့ tab မွာျမင္ရမယ့္ string ျဖစ္ျပီး (ဥပမာ Page 1) ေနာက္တစ္ခုကေတာ့ tab ကုိႏွိပ္ရင္
228
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Layout file ၁ခုျဖစ္တဲ့ P1, P2, P3 တုိ႕ကို TabHost ေပၚေရာက္ေအာင္
ေအာက္ပါအတုိင္းတင္ေပးပါ၉
Activity.LoadLayout ("Main")
tbhPages.AddTab("Page 1","Page1")
tbhPages.AddTab("Page 2","Page2")
tbhPages.AddTab("Page 3","Page3")
End Sub
ေတြကိုျမင္ရပါလိမ့္မယ္၉
ပံု ၅-ဿ၄
229
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 7.8
image file ၀ခုကို File manager ကေန ထည့္ထားပါ (ဥပမာ ic.png, ic_selected.png)၉ တစ္ခုက
Tab ကုိ select မလုပ္မီျပမယ့္ icon ျဖစ္ျပီး ေနာက္တစ္ခုက tab ကုိ select လုပ္ျပီးေနာက္ျမင္ရမယ့္
icon ျဖစ္ပါတယ္၉
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: UserInterfaceTabHost
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
End Sub
230
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Globals
Sub Globals
End Sub
Activity_Create
ic.png နဲ႕ ic_selected.png image ေတြကို bmp1 နဲ႕ bmp2 ထဲအသီးသီး ထည့္ပါ၉
TabHost ထဲကို icon ၀ခုပါတဲ့ tab ထည့္ပါ၉ AddTabWithIcon method မွာ parameter
၂ခုယူပါတယ္၉
Event name
Bitmap
Bitmap
အတြက္ dark ျဖစ္တဲ့ icon ကိုသံုးျပီး not selected icon အတြက္ light ျဖစ္တဲ့ icon
ကုိသံုးသင့္ပါတယ္၉
231
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
AddTab method မွာ parameter ၀ခုယူပါတယ္၉ Event name နဲ႕ layout file name ပါ၉
အထက္ပါ code မွာ TabHost1 ထဲကို tab ၁ခုထည့္ပါတယ္၉ ပထမတစ္ခုမွာ icon ၀ခုပါျပီး
က်န္ ၀ခုမွာေတာ့ icon မထည့္ထားပါဘူး၉ ပထမ tab ကုိ ႏွိပ္ရင္ P1 layout ျမင္ရမယ္၉ ဒုတိယ tab
ပံု ၅-ဿ၅
ToogleButton
ON/OFF mode ၀ခုပါတဲ့ button ျဖစ္ပါတယ္၉ ToogleButton ကို click လုပ္ရင္ မူလက ON
ဆုိရင္ OFF ျဖစ္သြားျပီး၈ မူလက OFF ဆုိရင္ ON ျဖစ္သြားပါမယ္၉
232
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 7.9
Play ခ်င္တဲ့ audio file ကုိ File manager ကေနထည့္ထားပါ၉ (ပံု ၅.ဿ၆) အတုိင္း layout
တစ္ခုဖန္တီးပါ၉
ပံု ၅-ဿ၆
233
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Properties of Views
234
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
235
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၀၁
Layout Name: 1
Sub Process_Globals
End Sub
236
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
View ေတြကုိ Globals မွာ Dim လုပ္ပါ၉
Sub Globals
End Sub
FirstTime = True ျဖစ္ရင္ MediaPlayer1 နဲ႕ Timer1 တုိ႕ကို initialize လုပ္ပါ၉ Play ခ်င္တဲ့
audio file ကုိ load လုပ္ပါ၉ Timer1 ကုိ initialize လုပ္တဲ့အခါ interval ပါ သတ္မွတ္ေပးပါ၉ (ဥပမာ
1000)
If FirstTime Then
MediaPlayer1.Initialize ( )
End If
Activity.LoadLayout ("1")
237
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Looping_CheckedChange (Looping.Checked)
Activity resume လုပ္စဥ္မွာ autdio file ကုိ စတင္ play ပါမယ္၉ အဲဒီအခ်ိန္မွာ
အသံစတင္ၾကားရပါမယ္၉
MediaPlayer1.Play
Timer1.Enabled = True
ျပီးရင္ t1_Tick event ကုိ ေခၚပါတယ္၉ t1 ရဲ႕ သတ္မွတ္ထားတဲ့ interval (ဥပမာ 1 second)
ျပည့္မွ ျဖစ္ေပၚရမယ့္ Tick event ကုိ အခ်ိန္မေစာင့္ဘဲ code ေရးျပီး event sub
ကိုေခၚလိုကတ
္ ာျဖစ္ပါတယ္၉
t1_Tick
ပံု ၅-၀၂
If MediaPlayer1.IsPlaying Then
238
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဆိုေသာ္လည္းေနရာမဟုတ္ဘဲ အခ်ိန္သာျဖစ္ပါတယ္၉ ဥပမာ Audio ဖုိင္ကုိ play ေနတာ 5 seconds
အျဖစ္သတ္မွတ္ေပးပါ၉
လိုက္ေရြ႕သြားမွာျဖစ္ပါတယ္၉
မွာျပပါ၉
ပံု ၅-၀၃
Activity_Pause
pause လုပ္ႏုိင္မွာေၾကာင့္ပါ) Play ေနတာဆိုရင္ MediaPlayer1 ကုိ pause လုပ္ပါ၉ timer1 ကုိလည္း
disable လုပပ
္ ါ၉ ဒါေၾကာင့္ Activity pause လုပ္ထားစဥ္မွာ timer1 လည္း အလုပ္မလုပ္ေတာ့ပါဘူး၉
239
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Pause (UserClosed As Boolean)
timer1.Enabled = False
End Sub
barVolume_ValueChanged
ပံု ၅-၀၄
event ျဖစ္ေပၚလာရင္ SetVolume method ကုိ ေခၚပါ၉ SetVolume method မွာ parameter
၀ခုယူပါတယ္၉ Left နဲ႕ Right volume ပါ၉ 0 နဲ႕ 1 ၾကားက value တစ္ခုေပးရမယ္၉ ဒီေတာ့
barVolume ရဲ႕ အခုေျပာင္းလုိက္တဲ့ value ကုိ 100 နဲ႕စားျပီး ရလာဒ္ကို Left volume အျဖစ္ေရာ၈
End Sub
barPosition_ValueChanged
sub မွာ parameter ၀ခုရွိပါတယ္၉ Value နဲ႕ UserChanged ပါ၉ Value က barPosition
240
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ရဲ႕အခုေျပာင္းလုက
ိ ္တဲ့ value ျဖစ္ျပီး UserChanged ကေတာ့ True/False ျဖစ္ပါမယ္၉ UserChanged
Position ကုိတြက္ေပးပါ၉
အဲဒီအခ်ိန္မ်ိဳးမွာ user က position change လိုက္ရင္ audio ကုိ play ပါ၉ ျပီးရင္ barPosition ကုိ
MediaPlayer1.Play
End If
t1_Tick
End Sub
Looping_CheckedChange
ျဖစ္ေပၚပါမယ္၉ Toogle button ကုိ check လုပ္ထားရင္ Checked = True ျဖစ္မယ္၉ Uncheck
MediaPlayer1 ရဲ႕ Looping property ကုိ Checked ထဲက value (True/Fale) နဲ႕ set လုပ္ပါတယ္၉
မွာျဖစ္ပါတယ္၉
241
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Looping_CheckedChange (Checked As Boolean)
MediaPlayer1.Looping = Checked
End Sub
ConvertToTimeFormat
Second ကို minute ဖြဲ႕ဘုိ႕ 60 နဲဲ႕စားပါတယ္၉ Floor method ကေတာ့ (ဥပမာ Floor (5.3)
ဆိုတာကေတာ့ အၾကြင္းကိုတြကတ
္ ာပါ၉ ဥပမာ 6 Mod 5 = 1 ျဖစ္ပါတယ္၉
242
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
NumberFormat method မွာ parameter ၁ခုရွိပါတယ္၉ Number, MinimumIntegers နဲ႕
ပံု ၅-၀၅
format လုပ္ေပးပါ၉
NumberFormat (minutes, 1, 0)
NumberFormat (seconds, 2, 0)
Complete Code
Sub Process_Globals
Dim MediaPlayer1 As MediaPlayer
Dim timer1 As Timer
End Sub
243
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Globals
Dim barPosition As SeekBar
Dim barVolume As SeekBar
Dim lblPosition As Label
Dim Looping As ToggleButton
End Sub
Sub Activity_Resume
MediaPlayer1.Play
timer1.Enabled = True
t1_Tick
End Sub
Sub t1_Tick
If MediaPlayer1.IsPlaying Then
barPosition.Value = MediaPlayer1.Position / MediaPlayer1.Duration * 100
244
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
lblPosition.Text = "Position: " & _
ConvertToTimeFormat (MediaPlayer1.Position) & _
" (" & ConvertToTimeFormat(MediaPlayer1.Duration) & ")"
End If
End Sub
245
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၀၆
WebView
Html page ေတြကိုျပႏုိင္တဲ့ view ျဖစ္ပါတယ္၉
Example 7.10
တစ္ခု create လုပ္ပါ၉ Designer မွာ WebView တစ္ခုထည့္ပါ၉ Layout ကို Layout1 အမည္နဲ႕ save
ပါ၉ Notepad မွာေအာက္ပါ html code ကိုရိုက္ျပီး web.html အမည္နဲ႕ project folder ရဲ႕ Files
folder ေအာက္မွာထားပါ၉
<html>
<body>
</body>
</html>
IDE code editor မွာ ေအာက္ပါအတိုင္း ေရးျပီး run ပါ၉ ေခြးကေလးတစ္ေကာင္ ေျပးေနတာ
246
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Globals
End Sub
Activity.LoadLayout ("Layout1")
WebView1.Width = 100%x
WebView1.Height = 100%y
WebView1.LoadURL ("file:///android_asset/web.html")
End
ပံု ၅-၀၇
247
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.1.4. Tools Menu
ပံု ၅-၁ှ
Generate Members: View ေတြကို declare လုပ္ရန္နဲ႕ event sub frame မ်ား create လုပ္ရန္၉
Code မွာသံုးမယ့္ view ေတြကို check လုပ္ပါ၉ Event sub frame လိုအပ္တဲ့ view (ဥပမာ
btnAction) အတြက္ လုိခ်င္တဲ့ event (ဥပမာ Click) ကို check လုပ္ပါ၉ ျပီးရင္
Check လုပ္လုိက္တဲ့ view ေတြအတြက္ reference ကုိ code editor ရဲ႕ Globals sub မွာ generate
လုပ္ေပးပါလိမ့္မယ္၉ ဥပမာ
248
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim lblMathSign As Label
View တစ္ခုရဲ႕ event ကို check လုပ္ရင္ အဲဒီ event အတြက္ event sub frame ကို
Sub btnAction_Click
End Sub
ပံု ၅-၁ဿ
249
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Bring To Front & Send To Back: View ၀ခုထပ္ေနတဲ့အခါ view တစ္ခုကို select လုပ္ျပီး
Bring to Front ကုိ click ပါ၉ Selected view ဟာ မ်က္ႏွာစာကို ေရာက္လာပါမယ္၉ Send To Back
ပံု ၅-၁၀
Remove Selected Views: ဖ်က္ခ်င္တဲ့ view/views ကို select လုပ္ျပီး Remove Selected Views
Duplicate Selected Views: မူလ view/views ကုိ select လုပ္ျပီး Duplicate Selected Views ကုိ
ပံု ၅-၁၁
ပံု ၅-၁၂
250
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Connect to Device/Emulator: Designer ကုိ device/emulator နဲ႕ခ်ိတ္ဆက္ရန္၉ PC မွာ device
ခ်ိတ္ဆက္ခ်င္တဲ့ တစ္ခုကိုေရြးေပးပါ၉
ပံု ၅-၁၃
IDE နဲ႕ device/emulator ကုိခ်ိတ္ရန္ Chain icon ကုိ double click လုပ္ပါ၉ Status မွာ
(ပံု ၅-၁၄)
251
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၁၄
Main tab မွာ Designer state ကိုျပပါတယ္၉ View ေတြကိုထည့္ျခင္း၈ ဖ်က္ျခင္း၈ property
ျပင္ျခင္းကို Main tab မွာလုပ္ရမယ္၉ Designer ရဲ႕ ဘယ္ဘက္ျခမ္းတြင္ layout ထဲမွာရွိတဲ့ view
ပံု ၅-၁၅
252
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အလယ္မွာေတာ့ selected view ရဲ႕ property ကိုျပထားျပီး လိသ
ု လိုျပင္ႏုိင္ပါတယ္၉
(ပံု ၅-၁၆)
ပံု ၅-၁၆
ထပ္ထည့္ရန္ျဖစ္ပါတယ္၉
ပံု ၅-၁၇
253
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.3. Properties List
View တစ္ခုကို select လုပ္ထားရင္ view ရဲ႕ property ေတြကို properties list
Main
Common properties
ပံု ၅-၂ှ
Main
Name: View name ပါ၉ ၾကိဳက္ရာအမည္ ေပးႏုိ္င္ပါတယ္၉ သို႕ေသာ္ အမည္ေပးတဲ့အခါ view type
254
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အမည္ေပးမယ္ဆုိရင္ btn ဆိုတဲ့ character ၁လံုးကိုေရွ႕မွာထားမယ္၉ Ok button အျဖစ္သံုးမွာဆိုရင္
အမည္ကို btnOk လို႕ေပးပါ၉ Cancel button ဆိုရင္ btnCancel လို႕ေပးပါ၉ Title ကုိေဖာ္ျပမယ့္
Type: View ရဲ႕ type ကိုေဖာ္ျပပါတယ္၉ ဥပမာ view ဟာ Button လား၈ Label လားအစရွိသည္ျဖင့္
Event Name: View ရဲ႕ event name ျဖစ္ပါတယ္၉ Default အေနနဲ႕ event name ဟာ view name
ရွိတတ္ပါတယ္၉ ဥပမာ Button1, Button2, Button3 ဆိုတဲ့ Button view ၁ခုလံုးရဲ႕ event name
Parent: Parent view ရဲ႕ name ကိုေပးရမယ္၉ View ကုိဘယ္ container ေပၚမွာထားမလည္း၉
ဥပမာ Button1 ကုိ Activity ေပၚမွာထားမယ္ဆိုရင္ Button1 ရဲ႕ parent ဟာ Activity ပါ၉ Button1
Common properties
ပံု ၅-၂ဿ
255
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Left: Parent ရဲ႕ left နဲ႕ view ရဲ႕ left ၾကားအကြာအေှး၉ Unit က dip ပါ၉
ပံု ၅-၂၀
Enabled: View ကုိ enable ျဖစ္ေစရန္ True ကိုေရြးပါ၉ Disable လုပ္ရန္ False ကိုေရြးပါ၉
Visible: View ကုိ ျမင္ရေအာင္ျပခ်င္ရင္ True ကိုေရြးပါ၉ Hide လုပ္ထားခ်င္ရင္ False ကိုေရြးပါ၉
Project ထဲကို image file ေတြထည့္ရန္ AddImages button ကုိ click ပါ၉ ျပန္ဖ်က္လိုပါက
ဖ်က္လိုေသာဖုိင္ကို ေရြးျပီး Remove selected button ကုိ click ပါ၉ (ပံု ၅-၂၁)
256
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၂၁
Layout file တစ္ခုမွာ layout variant အမ်ိဳးမ်ိဳး ရွိႏုိ္င္ပါတယ္၉ Application ကုိ run တဲ့
လုပ္ျပမွာျဖစ္ပါတယ္၉
Example 7.11
Application ကုိ portrait mode မွာ run သည္ျဖစ္ေစ၈ landscape mode မွာ run
257
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၂၂
ပံု ၅-၂၃
258
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Designer မွာ (ပံု ၅-၂၄) မွာျပထားတဲ့အတုိင္းေတြ႕ရမယ္၉
ပံု ၅-၂၄
ပံု ၅-၂၅
Form ကုိ resize ျပန္လုပ္ရန္ [Tools > Resize Form To Fit Layout] ကိုေရြးပါ၉ ျပီးရင္
ေနရာျပန္ခ်ပါ၉
259
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၂၆
ျမင္ရပါမယ္၉
ပံု ၅-၂၇
Program ကုိ run ျပီး device ကုိ portrait ေရာ landscape မွာပါ ထားၾကည့္ပါ၉ Portrait
မွာထားရင္ 320 x 480 layout variant မွာ design လုပ္ထားတဲ့ layout ကုိျမင္ရျပီး landscape
မွာထားရင္ 480 x 320 layout variant မွာ design လုပ္ထားတဲ့ layout ကုိျမင္ရမွာျဖစ္ပါတယ္၉
260
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 7.12
TestLayout.b4a file ကို ဖြင့္ပါ၉ Abstract Designer မွာ (ပံု ၅-၃ှ) မွာျပထားတဲ့အတိုင္း
ျမင္ရမယ္၉
ပံု ၅-၃ှ
Designer window မွာ [Tools > Resize Form to Fit Layout] ကိုေရြးပါ၉ (ပံု ၅-၃၀)
အတိုင္းျဖစ္သြားမယ္၉
261
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တစ္ခထ
ု က္မက ထပ္ထည့္ႏုိ္င္ပါတယ္၉ Layout variant အသစ္ထပ္ထည့္ရန္ New Variant button
ပံု ၅-၃၁
262
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၃၂
(ပံု ၅-၃၂) မွာျပထားတဲ့အတုိင္းေရြးျပီး Ok button ကုိ click ပါ၉ (Landscape mode အတြက္
ပံု ၅-၃၃
ကိုျမင္ရမွာ မဟုတ္ေတာ့ဘူးေနာ္၉
263
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၃၄
ပံု ၅-၃၅
264
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၃၆
ျပီးရင္ program ကုိ 320 x 480 resolution ရွိတဲ့ device/emulator မွာ run ပါ၉ Portrait
ပံု ၅-၃၇
265
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Landscape mode မွာ (ပံု ၅-၄ှ) အတုိင္းျဖစ္မယ္၉
ပံု ၅-၄ှ
ေနာက္တစ္ခါ ဒီ့ထက္ size ၾကီးတဲ့ device တစ္ခုမွာ run ၾကည့္ပါ၉ (ပံု ၅-၄ဿ) နဲ႕ (ပံု ၅-၄၀)
ပံု ၅-၄ဿ
266
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၄၀
Activity.Height > Activity.Widht ျဖစ္ရင္ (portrait mode ျဖစ္ရင္) line 25 နဲ႕ 26 ကို
execute လုပ္မယ္၉ မဟုတ္ရင္ (landscape mode ဆိုရင္) ေတာ့ line 27 to 30 ကို execute
လုပ္မယ္၉ ျပီးရင္ program ကုိ run ပါ၉ (ပံု ၅-၄၁) နဲ႕ (ပံု ၅-၄၂) မွာျပထားတဲ့အတုိင္း
267
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၄၁
ပံု ၅-၄၂
268
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.6. Abstract Designer
မွာ design လုပ္ရတာပိုျမန္ပါတယ္၉ View တစ္ခုကို click လုိက္ရင္ သူ႕ရဲ႕ property ေတြကို
ပံု ၅-၄၄
ပံု ၅-၄၃
269
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.6.1. Menu
Layout
ပံု ၅-၄၅
270
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Zoom Tools
View တစ္ခုကုိ right click လုပ္ရင္ (ပံု ၅-၅ှ) မွာျပထားတဲ့အတိုင္း context menu
ေပၚလာမယ္၉
ပံု ၅-၅ှ
ေတြထပ္ေပၚလာမယ္၉
271
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၅ဿ
„Dim btnTest1 As Button‟ ကုိေရြးရင္ code editor မွာ btnTest1 ကို declare
လုပ္ျပီးျဖစ္မယ္၉
Sub Globals
End Sub
272
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Down ကုိေရြးရင္ Down event အတြက္ event sub frame ရမယ္၉
Sub btnTest1_Down
End Sub
Sub btnTest1_Up
End Sub
Sub btnTest1_Click
End Sub
Sub btnTest1_LongClick
End Sub
View ကုိ select လုပ္ရန္ mouse နဲ႕ click ပါ၉ တစ္ခုထက္ပိုျပီး select လုပ္ခ်င္ရင္ ပထမဆံုး
view ကုိ select လုပ္ျပီးေနာက္ Ctrl key ကုိႏွိပ္ထားျပီး (မလႊတ္ဘ)ဲ ေနာက္ထပ္ view တစ္ခုခ်င္းကို
mouse နဲ႕ click သြားပါ၉ Select လုပ္ျပီးေနာက္ view ေပၚမွာ right click လုပ္ရင္ (ပံု ၅-၅၀)
273
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၅၀
ပံု ၅-၅၁
%x, %y
ဥပမာ
View ရဲ႕ width ကုိ 50%x လို႕သတ္မွတ္ရင္ Activity width ရဲ႕ တစ္ှက္ျဖစ္ပါတယ္၉
View ရဲ႕ height ကုိ 25%y လို႕သတ္မွတ္ရင္ Acitivity height ရဲ႕ 25% ျဖစ္ပါတယ္၉
device ေပၚမူတည္ပါတယ္၉
274
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 7.13
lblTitle
lblPanelTitle
btnTest
pnlTest
ပံု ၅-၅၂
Sub Globals
275
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim pnlTest As Panel
End Sub
သတ္မွတ္တယ္၉
လို႕သတ္မွတ္တယ္၉
ထဲထည့္တယ္၉
သတ္မွတ္တယ္၉
btnTest လို႕ေပးတယ္၉
276
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
btnTest.Text = "Test" Button မွာျမင္ရမယ့္ text ကုိ Test
လို႕သတ္မွတ္တယ္၉
lblPanelTitle.Gravity = Gravity.CENTER_HORIZONTAL +
Gravity.CENTER_VERTICAL
End Sub
AddView method မွာ parameter 5 ခုယူပါတယ္၉ View, Left, Top, Widht, Height
ျဖစ္ပါတယ္၉ Left, Top က view ရဲ႕ position ျဖစ္ျပီး width, Height ကေတာ့ view ရဲ႕ dimension
ျဖစ္ပါတယ္၉
277
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
7.8. Designer Scripts
ကုိအသံုးျပဳျခင္းပါဘဲ၉
Layout file တုိင္းမွာ script code ပါပါတယ္၉ Script ကို Designer window ရဲ႕ Designer
ပံု ၅-၅၃
278
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Script ၀မ်ိဳးရွိပါတယ္၉ Variant အားလံုးအတြက္သံုးမယ့္ General script နဲ႕ current variant
Properties:
Width / Height
Text
Image
Visible
Methods
Keywords
Min / Max
AutoScale
AutoScaleAll
AutoScaleRate
ActivitySize
If .. Then
279
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Example 7.14
ပံု ၅-၅၄
btnLeft နဲ႕ btnRight ကိုအေပၚပိုင္းမွာ ထားမယ္၉ btnDown ကို bottom မွာထားျပီး သူ႕ရဲ႕
ToggleButton1 ကို Activity ရဲ႕အလယ္တည့္တည့္မွာ ထားမယ္၉ Layout file name ကုိ main
280
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
လုိ႕ေပးျပီး Activity_Create မွာ Activity.LoadLayout(“main”) လုိ႕ေရးပါ၉ Designer window မွာ
အျပည့္ေနရာယူပါတယ္၉
အျပည့္ေနရာယူပါတယ္၉
အျပည့္ေနရာယူပါတယ္၉
ၾကားလြတ္တဲ့ေနရာအားလံုးယူလိုက္ပါတယ္၉
ToggleButton1.HorizontalCenter = 50%x
ToggleButton1.VerticalCenter = 50%y
281
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ F5 ကိုႏွိပ္ျပီး script code ေတြကို run လိုက္ပါ၉ (ပံု ၅-၅၅) မွာျပထာတဲအ
့ တုိင္း
ေနရာခ်ေပးသြားပါလိမမ
့္ ယ္၉
ပံု ၅-၅၅
ျပီးရင္ program ကုိ run ပါ၉ (ပံု ၅-၅၆) မွာျပထားတဲ့အတုိင္း ျမင္ရမယ္၉ အျခား device
ေတြသံုးျပီး စမ္းႏုိင္ပါတယ္၉
282
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၅၆
7.9. Anchor
Application ကုိ ဘယ္ device မွာ run သည္ျဖစ္ေစ view ကို Activity ရဲ႕ (Left, Right,
property ၀ခုရွိပါတယ္၉
Horizontal Anchor
Vertical Anchor
283
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Horizontal Anchor
ပံု ၅-၅၇
LEFT
o View ရဲ႕ left edge ကို parent view (ဥပမာ Activity) ရဲ႕ left edge နဲ႕ anchor
မွာေပးထားတဲ့အတုိင္းျဖစ္ပါမယ္၉
ဥပမာ
View
Left = 50
RIGHT
o View ရဲ႕ right edge ကို parent view ရဲ႕ right edge နဲ႕ anchor လုပ္ေပးပါတယ္၉
BOTH
284
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Vertical Anchor
ပံု ၅-၆ဿ
TOP
BOTTOM
BOTH
တူပါတယ္၉)
device ရဲ႕ size ေပၚမူတည္ျပီး view size နဲ႕ text size ကုိေျပာင္းႏုိင္တဲ့နည္း ရွိပါေသးတယ္၉
rate = 0.3
285
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Auto scale function ၁ခုရွိပါတယ္၉
AutoScaleRate (rate)
AutoScale (View)
AutoScaleAll
ကိုအေျခခံထားပါတယ္၉
ကိုသတ္မွတ္ေပးတာပါ၉ Rate value ဟာ 0 နဲ႕ 1 ၾကားျဖစ္ရပါမယ္၉ 0.2 နဲ႕ 0.5 ၾကား value
AutoScaleRate (0.5)
AutoScale (View) ကေတာ့ ဘယ္ view ကို auto scale လုပ္မယ္ဆိုတာ သတ္မွတ္တာပါ၉
AutoScale (btnTest1)
286
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
AutoScaleAll ကေတာ့ layout မွာပါတဲ့ view အားလံုးကို scale လုပ္တာပါ၉
Auto scale function ကုိ designer script မွာေအာက္ပါပံုစံမ်ိဳး ေရးရပါမယ္၉ Rate value ကုိ
0 ကေန 1 ၾကားအမ်ိဳးမ်ိဳးေပးျပီးစမ္းၾကည့္ပါ၉
AutoScaleRate (0.5)
AutoScaleAll
Example 7.15
(ပံု ၅-၆၀) မွာျပထားတဲ့အတုိင္း layout တစ္ခု create လုပ္ျပီး layout name ကုိ Main လုိ႕ေပးပါ၉
ပံု ၅-၆၀
287
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Designer Script
Main layout ရဲ႕ designer script code ကို (ပံု ၅-၆၁) မွာျပထားတဲ့အတုိင္းေရးပါ၉
ပံု ၅-၆၁
(ပံု ၅-၆၂) မွာျပထားတဲ့အတုိင္း ေနာက္ထပ္ layout တစ္ခု create လုပ္ျပီး layout name ကုိ
Panel လုိ႕ေပးပါ၉
ပံု ၅-၆၂
288
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Designer Script
Panel layout ရဲ႕ designer script code ကို (ပံု ၅-၆၃) မွာျပထားတဲ့အတုိင္းေရးပါ၉
ပံု ၅-၆၃
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: AutoScaleExample1
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
End Sub
289
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Globals
End Sub
Activity.LoadLayout ("Main")
scvTest.Panel.LoadLayout ("Panel")
scvTest.Panel.Height = pnlSetup.Height
End Sub
Sub Activity_Resume
End Sub
End Sub
အထက္ပါ application ကုိ 800/1280 10'' screen emulator မွာ rate value
ေတြ႕ရမွာျဖစ္ပါတယ္၉ 4800/800 7'' screen emulator မွာ rate value အမ်ိဳးမ်ိဳးေျပာင္းျပီး run
screen emulator မွာ rate value အမ်ိဳးမ်ိဳးေျပာင္းျပီး run ၾကည့္တဲ့အခါ (ပံု ၅-၇၆) မွာ
290
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
291
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
292
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
293
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-၇၆
Example 7.16
Example 7.15 မွာေရးထားတဲ့ application ကုိ landscape mode မွာ run ရင္
ေတြေပ်ာက္ေနမွာပါ၉
ပံု ၅-၇၇
294
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဒါေၾကာင့္ landscape orientation အတြက္ layout variant တစ္ခုထပ္လုပ္ပါမယ္၉ New
variant မွာ button ေတြပါတဲ့ ToolBox ကို screen ရဲ႕ညာဘက္ျခမ္းကို (ပံု ၅-ဿှှ)
မွာျပထားတဲ့အတုိင္း ေရႊ႕လိုက္ပါ၉
ပံု ၅-ဿှှ
AutoScaleRate (0.5)
AutoScaleAll
lblTitle.HorizontalCenter = 50%x
lblSubTitle.HorizontalCenter = 50%x
pnlToolBox.HorizontalCenter = 50%x
295
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ToolBox Panel ရဲ႕ bottom ကို Activity bottom မွာထားပါ၉
pnlToolBox.Bottom = 100%y
scvTest.HorizontalCenter = 50%x
AutoScaleRate (0.5)
AutoScaleAll
Activity left နဲ႕ ToolBox ၾကားကလြတ္တဲ့ေနရာ center မွာ lblTitle နဲ႕ lblSubTitle
ကိုထားပါ၉
lblTitle.HorizontalCenter = pnlToolBox.Left / 2
lblSubTitle.HorizontalCenter = pnlToolBox.Left / 2
pnlToolBox.VerticalCenter = 50%y
296
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ToolBox ကို Activity ညာဘက္အစြန္းမွာ ကပ္ထားပါ၉
pnlToolBox.Right= 100%x
10dip) ထားပါ၉
AutoScaleRate (0.5)
AutoScaleAll
ဘာမွမေရးပါ၉
AutoScaleRate (0.5)
AutoScaleAll
ဘာမွမေရးပါ၉
297
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
landscape orientation မွာပါၾကည့္ေကာင္းတဲ့ layout ကိုရရွိမွာျဖစ္ပါတယ္၉
ပံု ၅-ဿှဿ
7.11. UI Cloud
298
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-ဿှ၀
ပံု ၅-ဿှ၁
299
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၅-ဿှ၂
300
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
တကယ့္ size ကုိသိခ်င္ရင္ အဲဒီပံုေပၚမွာ click လုပ္ၾကည့္ႏုိင္ပါတယ္၉
ပံု ၅-ဿှ၃
301
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 8
Tutorials
layout ကုိ emulator မွာလုပ္ျပပါမယ္၉ Desktop ေပၚက Basic4android ကို run ပါ၉
IDE menu မွာ [Tools >Run AVD Manager] ကို ေရြးပါ၉ (ပံု ၆-ဿ)
ပံု ၆-ဿ
302
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(ပံု ၆-၀) အတုိင္းေပၚလာရင္ Close button ကို click ပါ၉
ပံု ၆-၀
ပံု ၆-၁
303
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၂
ပံု ၆-၃
304
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Emulator ready ျဖစ္ေအာင္ ေစာင့္ပါ၉ အခ်ိန္အနည္းငယ္ ၾကာတတ္ပါတယ္၉ (ပံု ၆-၄)
ပံု ၆-၄
Project ကို save ရန္ MyFirstProgram ဆိုတဲ့ folder တစ္ခု create လုပ္ပါ၉ Project name
ပံု ၆-၅
305
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Package Nameေပးရန္
Project တုိင္းကို package name ေပးရမယ္၉ IDE menu မွာ [Project > Package Name]
ပံု ၆-၆
ပံု ၆-၇
306
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Application Label သတ္မွတ္ရန္
ပံု ၆-ဿှ
region ကုိ extend လုပ္မယ္၉ - ကို click ရင္ region ကုိ collapse လုပ္မယ္၉ (ပံု ၆-ဿဿ)
ပံု ၆-ဿဿ
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
307
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
လုိ႕ေျပာင္းလိုက္ပါ၉ User interface layout ျပဳလုပ္ဘုိ႕ IDE menu မွာ Designer ကုိ ေရြးပါ၉
(ပံု ၆-ဿ၀)
ပံု ၆-ဿ၀
ပံု ၆-ဿ၁
308
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
IDE နဲ႕ device/emulator မခ်ိတ္ဆက္ရေသးရင္ (ပံု ၆-ဿ၂) မွာျပထားတဲ့အတုိင္း
Disconnected ျဖစ္ေနမယ္၉
ပံု ၆-ဿ၂
(ပံု ၆-ဿ၃)
ပံု ၆-ဿ၃
309
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-ဿ၄
ပံု ၆-ဿ၅
ပံု ၆-ဿ၆
310
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Activity မွာေအာက္ပါ view ေတြထည့္ရမယ္၉
Label ဆုိတာ text ကိုျပဘို႕သုံးတဲ့ view, EditText ဆိုတာ text ရိုက္ထည့္ႏုိင္တဲ့ view,
Button ဆိုတာ user က action တစ္ခုခု (ဥပမာ click) လုပ္ႏုိင္တဲ့ view ျဖစ္ပါတယ္၉
ပံု ၆-ဿ၇
311
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Emulator မွာ Label တစ္ခုေပၚလာမယ္၉ (ပံု ၆-၀ှ)
ပံု ၆-၀ှ
ပံု ၆-၀ဿ
312
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Label size ကို လိုခ်င္တဲ့အရြယ္ရေအာင္ mouse နဲ႕ဆြဲျပင္ျပီး စိတ္ၾကိဳက္ေနရာကို
ပံု ၆-၀၀
(ပံု ၆-၀၁)
ပံု ၆-၀၁
ျပင္ႏုိင္ပါတယ္၉ Label name ကုိ lblNumber1 လို႕ေျပာင္းလုိက္ပါ၉ lbl ဆိုတာ ဒီ view ဟာ label
313
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၀၂
ပံု ၆-၀၃
314
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၀၄
ပံု ၆-၀၅
315
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အခုဆိုရင္ emulator မွာ (ပံု ၆-၀၆) အတုိင္းျဖစ္သြားမယ္၉
ပံု ၆-၀၆
ပံု ၆-၀၇
ပံု ၆-၁ှ
316
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Math sign (+) သေကၤတကိုျပဘို႕အတြက္ ေနာက္ထပ္ Label တစ္ခု ထပ္ထည့္မယ္၉
Emulator ေပၚက lblNumber1 ကုိ click ပါ၉ Designer မွာ [Tools > Duplicate Selected View]
ပံု ၆-၁ဿ
တတိယေျမာက္ Label ကုိ ပထမ Label နဲ႕ ဒုတိယ Label ၾကားမွာထားပါ၉ Name ကို
lblMathSign လို႕ေပးျပီး Text property မွာ „+‟ ေရးပါ၉ (ပံု ၆-၁၀) အတုိင္းျဖစ္သြားမယ္၉
ပံု ၆-၁၀
EditText view တစ္ခုထည့္ဦးမယ္၉ Designer menu မွာ [Add View > EditText]
317
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၁၁
EditText view ရဲ႕ property ကုိ (ပံု ၆-၁၂) အတုိင္း ျပင္ပါ၉ edt ဆိုတာ EditText မွန္း
ပံု ၆-၁၂
318
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Input Type မွာ NUMBERS လို႕ သတ္မွတ္လိုက္ရင္ EditText ထဲကို number ေတြသာ
ပံု ၆-၁၃
ပံု ၆-၁၄
319
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(ပံု ၆-၁၅) မွာျပထားတဲ့အတုိင္း Button property ေတြ ျပင္ပါ၉
ပံု ၆-၁၅
ပံု ၆-၁၆
320
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Comment အတြက္ Label တစ္ခု ထည့္ပါဦး၉ Properties ေတြကို (ပံု ၆-၁၇) အတုိင္း ျပင္ပါ၉
ပံု ၆-၂ဿ
ပံု ၆-၂၀
321
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
View ေတြကို code ထဲမွာေခၚသံုးဘို႕ဆိုရင္ declare လုပ္ေပးရမယ္၉ Button click event
ပံု ၆-၂၁
(ပံု ၆-၂၂) မွာျပထားတဲ့အတုိင္း check လုပ္ပါ၉ ျပီးရင္ [Generate members > Close]
ကိုေရြးပါ၉
ပံု ၆-၂၂
322
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
View ေတြကို check လုပ္လိုက္ျခင္းျဖင့္ Globals subroutine မွာ ေအာက္ပါအတုိင္း
generate လုပ္ေပးပါတယ္၉
View ရဲ႕ event ကုိ check လုပ္ျခင္းျဖင့္ event sub frame တစ္ခုကို ေအာက္ပါအတုိင္း
generate လုပ္ေပးပါတယ္၉
Sub btnAction_Click
End Sub
အခုကစျပီး code ေတြေရးေတာ့မွာမုိ႕ code editor ကိုသြားပါ၉ Layout file ကုိ Activity ေပၚ
လုပ္ရမယ္၉
Activity.LoadLayout("Main")
End Sub
323
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
problem ဆိုတာ 1 ကေန 9 ထိ random number „Number1‟ နဲ႕ „Number2‟ ကို generate လုပ္ျပီး
Sub Globals
End Sub
Sub New
lblNumber1.Text = Number1
lblNumber2.Text = Number2
lblComments.Text = "Enter the result" & CRLF & "and click on OK"
edtResult.Text = ""
End Sub
324
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
„New‟ subroutine ကုိ ေခၚမယ့္ code ကုိ Activity_Create subroutine မွာ
ေအာက္ပါအတုိင္း ေရးပါ၉
Activity.LoadLayout ("Main")
New
End Sub
lblComments.Text = "Enter the result" & CRLF & "and click on OK" ဆုိတာကေတာ့
and click OK
ေပါ့၉
Sub btnAction_Click
If edtResult.Text="" Then
Else
CheckResult
325
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
End If
Else
New
End If
End Sub
If edtResult.Text="" Then
ျပမယ္၉
CheckResult
New
326
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
If edtResult.Text = Number1 + Number2 Then
G O O D result
Click on NEW
W R O N G result
and click OK
လုိ႕ျပဘုိ႕ေအာက္ပါအတုိင္းေရးရမယ္၉
lblComments.Text = "W R O N G result" & CRLF & "Enter a new result" & CRLF &
327
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Complete Code
#ApplicationLabel: MyFirstProgram
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#RegionActivity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
328
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim lblNumber2 As Label
End Sub
Activity.LoadLayout("Main")
New
End Sub
Sub Activity_Resume
End Sub
End Sub
Sub New
lblNumber1.Text = Number1
lblNumber2.Text = Number2
lblComments.Text = "Enter the result" & CRLF & "and click on OK"
edtResult.Text = ""
End Sub
329
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub btnAction_Click
IfedtResult.Text=""Then
Else
CheckResult
EndIf
Else
New
EndIf
End Sub
Sub CheckResult
Else
EndIf
End Sub
330
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
8.2. Numeric Keyboard
SecondProgram ဆိုတဲ့ folder တစ္ခု လုပ္ပါ၉ MyFirstProgram ထဲက file နဲ႕ folder ေတြ
Designer ကုိ ဖြင့္ပါ၉ IDE နဲ႕ emulator ကုိ ခ်ိတ္ပါ၉ MyFirstProgram လုပ္ခဲ့တုန္းက number
အတုိင္းျဖစ္ေအာင္ လုပ္ၾကရမွာေနာ္၉
ပံု ၆-၂၃
331
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Package name ကုိလည္း ေျပာင္းဘုိ႕လုိေသးတယ္၉ (ပံု ၆-၂၄ နဲ႕ ၆-၂၅) မွာ ျပထားတဲ့
အတုင
ိ ္းလုပ္ပါ၉
ပံု ၆-၂၄
ပံု ၆-၂၅
ဖ်က္ျပီး Label တစ္ခုထပ္ထည့္ပါ၉ ဖ်က္ဘုိ႕က ေတာ့ emulator မွာ edtResult ကုိ select လုပ္ပါ၉
ပံု ၆-၂၆
332
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ Designer menu မွာ (ပံု ၆-၂၇) မွာျပထားတဲ့အတိုင္း ေရြးလုိက္ပါ၉
ပံု ၆-၂၇
ပံု ၆-၃ှ
lblNumber1 ကုိ select လုပ္ပါ၉ ျပီးရင္ (ပံု ၆-၃ဿ) မွာျပထားတဲ့အတုိင္း Label တစ္ခု ပြားယူလုိက္ပါ၉
333
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၃ဿ
ပံု ၆-၃၀
ပံု ၆-၃၁
334
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၃၂
ပံု ၆-၃၃
အတုိင္းျဖစ္လာမယ္၉
ျပီးရင္ keyboard အတြက္ key ေတြထားဘုိ႕ Panel view တစ္ခုထည့္ရေအာင္၉ Panel ကုိ
335
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၃၄
ပံု ၆-၃၅
(view တစ္ခုနဲ႕ ပတ္သက္ျပီး တစ္စံုတစ္ခု လုပ္ခ်င္တိုင္း အဲဒီ view ကုိအရင္ select လုပ္ရမယ္ဆိုတာ
ပံု ၆-၃၆
ပံု ၆-၃၇
336
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
(ပံု ၆-၃၇) မွာျပထားတဲ့အတုိင္း Ok button ရဲ႕ Parent ကုိ pnlKeyboard လို႕ေျပာင္းပါ၉
ပံု ၆-၄ှ
ပံု ၆-၄ဿ
337
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ (ပံု ၆-၄၁) မွာျပထားတဲ့ အတုိင္း Button တစ္ခုထပ္ထည့္ပါ၉ (ပံု ၆-၄၂)
ပံု ၆-၄၂
ပံု ၆-၄၃
338
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Panel ထဲမွာ 0 လို႕ေပၚေနတဲ့ Button တစ္ခုေရာက္သြားျပီေနာ္၉ (ပံု ၆-၄၄)
ပံု ၆-၄၄
ပံု ၆-၄၅
ပံု ၆-၄၇
339
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ျပီးရင္ (ပံု ၆-၅ှ) မွာျပထားတဲ့အတုိင္း parameter ေတြေျပာင္းလိုက္ပါဦး၉ (ပံု ၆-၅ဿ)
အတုိင္းျဖစ္သြားမယ္ေနာ္၉
ပံု ၆-၅၀
ပံု ၆-၅ဿ
ေနာက္ထပ္ Button တစ္ခု ရေအာင္ပြားပါဦး၉ အသစ္ရလာတဲ့ Button ကို select လုပ္ျပီး သူ႕အတြက္
ပံု ၆-၅၁
340
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၅၂
ျဖစ္သြားျပီေနာ္၉
ပံု ၆-၅၃
341
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အခု code ေတြ စေရးရေအာင္၉
Globals
btnEvent_Click
ေတြေရးေတာ့မယ္၉ BtnAction (OK button) ကလြဲျပီး က်န္ Button အားလံုး ရဲ႕ event name ကို
btnEvent လုိ႕ေပးခဲ့တာေနာ္၉ မေသခ်ာရင္ Button ေတြရဲ႕ property ကုိ ျပန္ၾကည့္ပါ၉ အဲဒီမွာ Event
click တဲ့အခါေဆာင္ရြက္ေပးရမယ့္ code ေတြကို Sub btnEvent_Click နဲ႕ End Sub ၾကားမွာ
ေရးရမယ္၉
Sub btnEvent_Click
Send = Sender
Select Send.Tag
Case "BS"
lblResult.Text=lblResult.Text.SubString2(0,lblResult.Text.Length- 1)
342
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
End If
End Select
If lblResult.Text.Length = 0 Then
btn0.Visible = False
Else
btn0.Visible = True
End If
End Sub
User click လုပ္လုိက္တဲ့ Button ကုိထည့္ဘုိ႕အတြက္ Button view „Send‟ ကို declare
လုပ္ပါတယ္၉
User က view တစ္ခုကို click လုပ္လုိက္ျပီဆိုရင္ အဲဒီ view ရဲ႕ object reference ဟာ
ရင္ အဲဒီ Button ရဲ႕ reference က Sender ထဲေရာက္သြားတယ္လို႕မွတ္ပါ) Send ထဲမွာ Sender ကုိ
assign လုပ္ပါ၉
Send = Sender
ဘာေၾကာင့္လည္းဆိုေတာ့ Send ထဲမွာ click ခံရေသာ Button ရွိေနမွာဆိုေတာ့ Send.Tag မွာ click
343
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ခံရေသာ Button ရဲ႕ Tag value ရွိေနမွာမုိ႕ပါ၉ Backspace button ကုိ click တာဆိုရင္ Send.Tag
property မွာ Backspace button ရဲ႕ Tag value ကုိ „BS‟ လို႕ေပးခဲ့လို႕ပါ၉
Select Send.Tag
Case "BS"
အနည္းဆံုး character တစ္ခုေတာ့ ရွိရမွာေပါ့၉ မရွိရင္ ဘာကုိ သြားဖ်က္မလဲ၉ ဒါေၾကာင့္ lblResult မွာ
character ကုိဖ်က္ေပးရမွာပါ၉
344
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
1234 12345 5
ဖ်က္ျပီးေနာက္ မဖ်က္မီ
4
Case "BS"
lblResult.Text=lblResult.Text.SubString2 (0,lblResult.Text.Length - 1)
End If
ေတြထဲကတစ္ခုခုဘဲေပါ့၉ Numeric button ကို click လုပ္ရင္ ဘာျဖစ္ေစခ်င္တာလဲ၉ အဲဒီ button ရဲ႕
value ကုိ lblResult.Text မွာေဖာ္ျပရမွာေပါ့၉ Calculator သံုးဘူးတယ္မုိ႕လား၉ 1 ကုိ click ရင္ Text
ကိုတြဲစပ္ေပးလိုက္တာပါ၉
345
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
lblResult ထဲမွာ character တစ္ခုမွမရွိေသးရင္ „0‟ Button ကုိသံုးစရာအေၾကာင္းမရွိလို႕
„0‟ နဲ႕ „စ‟ ေရးေလ့မရွိတာေၾကာင့္ပါ) Character တစ္ခုခုရွိေနျပီဆိုရင္ေတာ့ „0‟ Button ကုိ visible
ျပန္လုပ္ပါ၉
If lblResult.Text.Length = 0 Then
btn0.Visible = False
Else
btn0.Visible = True
End If
Sub New
သတ္မွတ္ေပးလုိက္ပါ၉
btn0.Visible = False
Sub CheckResult
346
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
အားလံုးျပီးရင္ run ၾကည့္ပါ၉ (ပံု ၆-၅၄) မွာျပထားတဲ့ပံုမ်ားအတုိင္း ျဖစ္ေနပါမယ္၉
စမ္းၾကည့္ၾကပါ၉
ပံု ၆-၅၄
button ကုိ click ရမယ္၉ User ထည့္လုိက္တဲ့ number ဟာ program မွာသတ္မွတ္ထားတဲ့ number
ျဖစ္ပါတယ္၉
(ပံု ၆-၅၆) မွာျပထားတဲ့ user interface layout တစ္ခု create လုပ္ပါ၉ Label, Button,
347
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၅၅
348
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၆-၆ှ
Layout file ကုိ create လုပ္ျပီးတာနဲ႕ေတာ့ application ကို run ရင္ screen
Activity.LoadLayout("Layout1")
End Sub
အခုေန program ကုိ run လုိက္ရင္ screen မွာ layout ကုိ ျမင္ရမွာျဖစ္ပါတယ္၉ ဒါေပမယ့္
349
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
click event ကို handle လုပ္ေပးမယ့္ code မေရးရေသးလိ႕ု ပါ၉ ဒါေၾကာင့္ Designer window မွာ
[Tools > Generate Members] ကို ေရြးျပီး btnGuess ရဲ႕ click event ကုိ check လုပ္ပါ၉ ျပီးရင္
„Generate members‟ button ကုိ ႏွိပ္ျပီး „Close‟ button ကုိ ဆက္ႏွိပ္ပါ၉ (ပံု ၆-၆ဿ)
ပံု ၆-၆ဿ
ေရးျပီးျဖစ္ေနတာ ေတြ႕ရပါမယ္၉
Sub btnGuess_Click
End Sub
Sub Globals
End Sub
350
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
MyNumber ထဲမွာ random number တစ္ခုထည့္ပါမယ္၉ Random number ဆိုတာ ကုိယ္
Rnd() ကုိ သံုးရပါမယ္၉ () ထဲမွာ parameter ၀ခု ေပးရပါမယ္၉ ပထမ parameter က ကိုယ္လိုခ်င္
တဲ့ number ရဲ႕ minimum value ကိုေပးရမွာ ျဖစ္ပါတယ္၉ ဒီ program မွာ 1 က 99 ထိ number
ေရးေပးရပါမယ္၉
ထည့္ေပးရပါမယ္၉
Activity ကုိ create လုပ္တုိင္း random number ကို ရခ်င္တာမို႕ အထက္ပါ code ကုိ
Activity.LoadLayout ("Layout1")
End Sub
351
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ရိုက္ထည့္မွာပါ၉ ဒါေၾကာင့္ edtNumber ထဲက number ကုိ ယူရပါမယ္၉ edtNumber ကို code မွာ
လုပ္ပါ၉
EdtNumber မွာ number တစ္ခု ရုိက္ထည့္ျပီးတာနဲ႕ btnGuess ကုိ click ရမွာပါ၉ ဒါေၾကာင့္
btnGuess Click event sub မွာ လိုအပ္တဲ့ code ေတြ စေရးပါမယ္၉ edtNumber.Text ဟာ
MyNumber ထက္ ၾကီးသလားစစ္ပါ၉ ၾကီးရင္ “My number is smaller” ဆိုတဲ့ toast message ကုိ
ကိုယ္ေပးခ်င္တဲ့ message ကုိ ေရးရပါမယ္၉ False ဆိုရင္ message ကုိ ခဏေလးသာျပျပီး True
Else
End If
352
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
EditText1 မွာ ေနာက္တစ္ၾကိမ္ထပ္ရိုက္ခါနီးရင္ အရင္ရိုက္ထားတဲ့ text ကုိ delete
edtNumber.SelectAll
Complete Code
Sub Globals
End Sub
Activity.LoadLayout ("Layout1")
End Sub
Sub btnGuess_Click
Else
353
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ToastMessageShow ("Well done.", True)
End If
edtNumber.SelectAll
End Sub
Program ကုိ run ရင္ (ပံု ၆-၆၀) အတုိင္း ျမင္ရမွာျဖစ္ပါတယ္၉ Number တစ္ခုျပီးတစ္ခု
ထည့္စမ္းၾကည့္ပါ၉
ပံု ၆-၆၀
354
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Chapter 9
မၾကာခဏေမးေလ့ရွိေသာေမးခြန္းမ်ား
ပံု ၉-ဿ
"Are you missing a library reference?" ဆုိတဲ့ message (ပံု ၉-၀) ေပၚလာတာကေတာ့
355
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ပံု ၉-၀
Tabs area မွာ „Libs‟ tab ကုိေရြးျပီးလိုအပ္တဲ့ library ေတြကို check လုပ္ေပးလိုက္ပါ။ ဘယ္
http://www.basic4ppc.com/android/documentation.html သို႕မဟုတ္
http://www.basic4ppc.com/android/wiki/index.php/Libraries မွာရယူႏုိင္ပါတယ္။
မ်ားအတြက္သာျဖစ္ပါတယ္။
ေအာက္ပါအဆင့္ေတြအတုိင္းလုပ္ပါ။
ဒီဖုိင၀
္ ခုကို (Standard B4A library ဆိုရင္) C:\Program Files\Anywhere
356
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ထဲမွာထားပါ။
9.5. စာေၾကာင္းရွည္ရင္ခြဲေရးျခင္း
Answ = Msgbox2 ("Do you want to quit the program", "A T T E N T I O N", "Yes", "",
"No", Null)
ကမွားျပီးႏွိပ္မိတာလား၊ တကယ္ႏွိပ္တာလားေသခ်ာေအာင္ထပ္ေမးႏိုင္ပါတယ္။
ထဲမွာ ဘယ္ key ကုိႏွိပ္လုိက္သလည္းဆိုတာ အရင္စစ္ရမယ္။ User ႏွိ္ပ္လုိက္တဲ့ key ရဲ႕ key code
လားဆိုတာေအာက္ပါအတုိင္းစစ္ရမယ္။
If KeyCode = KeyCodes.KEYCODE_BACK
357
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Back key ျဖစ္ေနရင္ "Do you want to quit the program?" ဆိုတဲ့ message box
If Answ = DialogResponse.NEGATIVEThen
Return True
End If
End If
Return False
End Sub
စစ္လို႕မရပါဘူး။
AddMenuItem
358
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
ဥပမာ
အထက္ပါအတုိင္းေရးျပီး run တဲ့အခါ menu button ကုိႏွိပ္ရင္ (ပံု ၉-၁) မွာကဲ့သို႕ Menu
item ႏွစ္ခုျမင္ရပါမယ္။
ပံု ၉-၁
359
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.8. Designer ကေန View ကုိဘယ္လိုဖ်က္မလဲ
Designer မွာ [Tools > Remove Selected Views] ကိုေရြးပါ။ (ပံု ၉-၂)
ပံု ၉-၂
IDE မွာ [Tools > IDE Options > Configure Process Timeout] ကိုေရြးပါ။
ပံု ၉-၃
360
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Timeout value ကို မူလေပးထားတာထက္ ပိုျပီး ေပးလိုက္ပါ။ (ပံု ၉-၄)
ပံု ၉-၄
Portrait: ေထာင္လိုက္ဘဲထားႏုိင္
Landscape: အလ်ားလိုက္ဘဲထားႏုိင္
Both: ႏွစ္မ်ိဳးလံုးေျပာင္းႏုိင္
0 Landscape
1 Portrait
-1 Both
361
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Process_Globals
End Sub
Sub Activity_Create(FirstTimeAsBoolean)
Activity.LoadLayout("Layout1")
End Sub
Actiivty1 ကေန Activity2 ကုိေခၚရင္ Activity2 ေပၚလာမယ္။ Activity2 မွာ Back key
ေအာက္ပါအတုိင္းေရးပါ။
StartActivity (Activity2)
Activity1.Finish
Sub btnScrShot_LongClick
Dim c As Canvas
362
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Dim dt As String
DateTime.DateFormat = "yyMMddHHmmss"
now = DateTime.now
Obj1.Target = Obj1.GetActivityBA
c.Initialize2 (bmp)
Obj2.Target = c
Out.Close
End Sub
device/emulator နဲ႕ခ်ိတ္ဆက္ျပီး compile လုပ္ရင္ apk file ကုိ device/emulator မွာ install
363
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
.apk ျဖစ္ပါတယ္္။ ဥပမာ project name ကုိ „GPSExample.b4a‟ လို႕ေပးထားရင္ apk name က
GPSExample.apk ျဖစ္ပါမယ္။
Sub Test1
End Sub
...
End Sub
364
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.16. Device ရဲ႕ Language နဲ႕ Country ရယူျခင္း
ကုိေရးပါ။ GetDefaultLanguage sub ကုိေခၚျပီး returned value ကုိ Logs area မွာျပပါ။
Log(GetDefaultLanguage)
End Sub
Sub GetDefaultLanguage
Dim r As Reflector
Return r.RunMethod("getDisplayName")
End Sub
ေတြကေအာက္ပါအတုိင္းျဖစ္ပါတယ္။
Deutsch (Österreich)
français (Suisse)
ဥပမာ project file name ကုိ „GPS Example.b4a‟ လုိ႕ေပးခဲ့ရင္ ရရွိလာတဲ့ apk file name ဟာ
result.apk လို႕ျဖစ္ေနမွာပါ။
365
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.18. ဘာေၾကာင့္ apk file name ဟာ xxx_DEBUG.apk ျဖစ္ရတာလဲ
ဆိုရင္ေတာ့ IDE tool bar ရဲ႕ debug mode မွာ Release/Release (obfuscated) ကိုေရြးျပီး run
ရမယ္။ Debug (legacy)/Debug (rapid) နဲ႕ run ရင္ေတာ့ apk file က xxx_DEBUG.apk
ရယ္လုိ႕ျဖစ္ေနမယ္။
ပံု ၉-၅
i = 10
Select True
Case (i < 9)
Log ("False")
Case (i = 10)
Log ("True")
End Select
Sub Globals
Dim numbers (10) As Int
End Sub
366
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub Activity_Create (FirstTime As Boolean)
For i = 0 To 9
numbers (i) = i + 1
Next
ShuffleArray (numbers)
For i = 0 To 9
Log (numbers (i))
Next
End Sub
Screen orientation ကုိေအာက္ပါ code သံုးျပီးသိႏုိင္ပါတယ္။ Activity ရဲ႕ width နဲ႕ height
367
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Log ("Landscape")
Else
Log ("Portait")
End If
End Sub
Sub Calculator
Dim i As Intent
i.SetComponent ("com.android.calculator2/.Calculator")
Try
StartActivity (i)
Catch
End Try
End Sub
Packages = Pm.GetInstalledPackages
368
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
calc စာလံုးပါတဲ့ package name ကိုရွာပါ။ ေတြ႕ရင္ သူ႕ရဲ႕ Intent ကုိသံုးျပီး calculator
application ကုိေခၚပါ။
Inte=Pm.GetApplicationIntent (st)
If Inte.IsInitialized Then
StartActivity (Inte)
Code အျပည့္အစံုကေအာက္ပါအတုိင္းျဖစ္ပါတယ္။
Sub Calculator
Dim Pm As PackageManager
Dim st As String
Packages = Pm.GetInstalledPackages
For i = 0 To Packages.size - 1
st = Packages.Get (i)
If Inte.IsInitialized Then
StartActivity (Inte)
Exit
End If
End If
Next
End Sub
369
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.23. Alpha/Red/Green/Blue
Alpha
Red
Green
Blue
End Sub
Return res
End Sub
370
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.24. Devcie အမ်ိဳးအစားရယူျခင္း
Else
Log (“phone”)
End If
End Sub
Dim lv As LayoutValues
lv = GetDeviceLayoutValues
End Sub
သာမန္အားျဖင့္ view တစ္ခုကို click ရင္ click event ျဖစ္ေပၚပါတယ္။ ဥပမာ Activity
ေအာက္ပါ code မွာေတာ့ Activity ကုိ click ရင္ Spinner Click event ျဖစ္ေပၚေအာင္
ဘယ္လိုလုပ္ရမယ္ဆိုတာျပထားပါတယ္။
371
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Globals
Sub Globals
Dim sp As Spinner
End Sub
Activity_Create
„sp‟ initialize လုပ္ျပီး item „a‟, „b‟, „c‟, „d‟ တုိ႕ကိုထည့္ထားပါ။ ျပီိးရင္ Spinner object „sp‟
sp.Initialize ("sp")
End Sub
Activity_Click
Activity_Click event sub မွာ OpenSpinner sub ကုိေခၚျပီး „sp‟ ကုိ pass လုပ္ပါ။
Sub Activity_Click
OpenSpinner (sp)
End Sub
372
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
OpenSpinner
OpenSpinner sub မွာ Reflector object „r‟ ကို declare လုပ္ျပီး spinner objet „s‟ ကုိ „r‟
လုပ္ေပးလိုက္ပါ။ အဲဒါဆိုရင္ Spinner Click event ျဖစ္ေပၚပါလိမ့္မယ္။ Program ကုိ run ျပီး
Activity မွာလြတ္တဲ့ေနရာကို click ပါ။ Spinner Click event ျဖစ္ေပၚျပီး Spinner ထဲမွာထည့္ထားတဲ့
Dim r As Reflector
r.Target = s
r.RunMethod ("performClick")
End Sub
373
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
getObject method ကိုေခၚျပီး result ကို Obj1 ရဲ႕ target အျဖစ္သတ္မွတ္ပါတယ္။
Obj1.Target = Obj1.RunMethod("getObject")
ကိုသုံးရမယ္။
Dim r As Reflector
r.Target = ScrollView1
DirRootExternal မွာ Images ဆိုတဲ့ directory ရွိမရွိ အရင္စစ္ပါတယ္။ မရွိရင္ DirRootExternal မွာ
End If
374
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
9.29. Full Screenျဖစ္ေစရန္ Code ျဖင့္ျပဳလုပ္ျခင္း
Dim i As Int
i = 1024 'FLAG_FULLSCREEN
If Active Then
Else
End If
End Sub
ရိုက္ထည့္ႏုိင္တယ္ဆိုတာ သတ္မွတ္ေပးႏုင
ိ ္တယ္။
INPUT_TYPE_NONE (စာရိုက္ခြင့္မျပဳ)
375
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
INPUT_TYPE_PHONE (Phone number ေတြသာရိုက္ခင
ြ ့္ျပဳ)
ဥပမာ
EditText1.InputType = EditText1.INPUT_TYPE_TEXT
Sub Process_Globals
End Sub
Sub Globals
End Sub
For i = 0 To files.Size - 1
Dim fs As FileAndTime
fs = files.Get(i)
Next
End Sub
376
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Sub ListFilesByDate (Folder As String) As List
sortedFiles.Initialize
For i = 0 To files.Size - 1
Dim fs As FileAndTime
sortedFiles.Add (fs)
Next
Return sortedFiles
End Sub
Device ရဲ႕ dpi value ကုိရယူရန္ Reflection library ကိုသံုးဘုိ႕လိုပါတယ္။ dpi ဆုတ
ိ ာ dots
per inch ပါ။ Device ရဲ႕ တစ္လက္မမွာရွိတဲ့ pixel အေရအတြက္ေပါ့။ 160 dpi ဆိုရင္ တစ္လမမွာ
Dim r As Reflector
r.Target = r.GetContext
377
ထားထားေစာလြင္ Basic4android ျဖင့္ Android Application ေရးနည္း (ဿ)
Xdpi = r.GetField ("xdpi")
line ကုိရွာခ်င္ရင္
အဲဒီဖုိင္ကိုဖြင့္ပါ။
378