Thursday, October 29, 2015

Multiple screens/pages အသံုးျပဳ ျခင္း

Multiple screens/pages အသံုးျပဳ ျခင္း

B4A မွာ Activity ေတြ ထပ္ထည့္ၿပီး Multiple screens အေနနဲ႔ သံုးခဲ့ၾကပါတယ္။ အခု BMP APK Creator 2.0 မွာ Main activity တခုပဲ အသံုးျပဳႏိုင္ပါေသးတယ္။ ကိုယ့္ရဲ့ app မွာ Multiple screens/pages သံုးခ်င္ရင္ Panels ေတြကို Base display အေနနဲ႔ Show/Hide လုပ္ၿပီး ဖန္တီးႏိုင္ပါတယ္။ ေအာက္က နမူနာ ပရိုဂရမ္ မွာ Two screens display အေနနဲ႔ သံုးျပထားပါတယ္။ Screen တခုကေန ေနာက္ screen တခုကို ကူးေျပာင္းဖို႔ Button တခုစီ ထည့္ျပထားပါတယ္။ Screen 2 ကေန Screen 1 ကို ေျပာင္းဖို႔ Button ကို ႏွိပ္ႏိုင္သလို ဖုန္းရဲ့ BACK_BUTTON ကိုလဲ ႏွိပ္ႏိုင္ပါတယ္။ Screen 1 မွာ BACK_BUTTON ကို ႏွိပ္ရင္ေတာ့ Activity Finish ျဖစ္သြားမွာ ျဖစ္ပါတယ္။ BACK_BUTTON ႏွိပ္တာကို သိႏိုင္ဖို႔ Events Sub အပိုင္းမွာ Sub Activity_KeyPress(key) နဲ႔ ဖမ္းရပါမယ္။ key=4 က BACK_BUTTON ျဖစ္ပါတယ္။

#######################
Main Code Section တြင္ ေရးရန္
#######################

AddPanel("pnl1", 0,0,100%x,100%y,"")
SetColor("pnl1",0,cGreen)

AddLabel("lbl1",10%x,30%y,80%x,20%y,"pnl1")
SetText("lbl1","This is screen 1")

AddButton("btn1",10%x,60%y,80%x,20%y,"pnl1")
SetText("btn1","Go to screen 2")

REM ********************************

AddPanel("pnl2", 0,0,100%x,100%y,"")
SetColor("pnl2",0,cRed)

AddLabel("lbl2",10%x,30%y,80%x,20%y,"pnl2")
SetText("lbl2","This is screen 2")

AddButton("btn2",10%x,60%y,80%x,20%y,"pnl2")
SetText("btn2","Go to screen 1")

SetVisible("pnl2",false)

current="pnl1"

#####################
Events and Subs Section တြင္ ေရးရန္
#####################

Sub Activity_KeyPress(key)
If key=4 Then
If current="pnl2" Then
current="pnl1"
Button_Click("btn2")
Else
ActivityFinish
End If
End If
End Sub

REM ********************************

Sub Button_Click(who)
Select who
Case "btn1"
SetVisible("pnl1",false)
SetVisible("pnl2",true)
current="pnl2"
Case "btn2"
SetVisible("pnl1",true)
SetVisible("pnl2",false)
current="pnl1"
End Select
End Sub

REM *******************************

သတိျပဳပါရန္
========

Sub Activity_KeyPress(key) ကို ထည့္လိုက္ရင္ BACK_BUTTON (=4) နဲ႔ MENU_BUTTON (=82) ကို code ေတြ ေရးေပးရပါမယ္။ MENU_BUTTON အတြက္ code မေရးခဲ့ ရင္ Menu ကို ေခၚလို႔မရေတာ့ပါဘူး။ ဒါကို ေျဖရွင္းႏိုင္ဖို႔ ေအာက္က code ကိုပါ ထည့္သြင္းေပးပါ။

REM in code section
REM --------------------
showMenu=true
REM set it to false if you don't want to show menu.

REM in Events & Subs section
REM --------------------------------

Sub Activity_KeyPress(key)
..
..
If key=82 Then
    If showMenu=true Then
        OpenMenu
    End If
End If
...
...
End Sub

No comments:

Post a Comment