Android Question Numeric Keypad and Label view

Declan

Well-Known Member
Licensed User
Longtime User
Can the Numeric Keypad be used as an "input" for a Label?
I successfully use the numeric keypad to input data into an EditText, but now need to change the EditText to a Label view.
 
One way is to handle the click event of the label and open an inputDialog in order to change its value. Another way is to create a panel with a custom keyboard. Have al look:
Code: Copy
Sub Globals
   Dim aLabel As Label
   Dim pnlNumKeyPad As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   aLabel.Initialize("aLabel")
   aLabel.Text="9999"
   Activity.AddView(aLabel,0,0,50%x,20%y)
   createPnlNumKeyPad
End Sub

Sub alabel_Click
   Dim anInputDialog As InputDialog
   anInputDialog.InputType=anInputDialog.INPUT_TYPE_NUMBERS
   anInputDialog.Input=aLabel.Text
   anInputDialog.Show("New Value:","Edit","OK","Cancel","",Null)
   If anInputDialog.Response=DialogResponse.POSITIVE Then
     Dim newValue As String=anInputDialog.Input
     aLabel.Text=newValue
   End If
End Sub

Sub createPnlNumKeyPad
   pnlNumKeyPad.Initialize("")
   Activity.AddView(pnlNumKeyPad,0,25%y,60%y,45%x)
   Dim cellheight As Int=pnlNumKeyPad.Height/4
   For i=0 To 9
     Dim btn As Button
     btn.Initialize("btnNumKeyPad")
     btn.tag=i
     btn.Text=i
     Dim yPos As Int=(i+2)/3
     Dim xPos As Int
     Dim cellWidth As Int
     If i=0 Then
       cellWidth=pnlNumKeyPad.Width
       xPos=0
     Else
       cellWidth=pnlNumKeyPad.Width/3
       xPos=(i+2)-yPos*3
     End If
     pnlNumKeyPad.AddView(btn,xPos*cellWidth,(3-yPos)*cellheight,cellWidth,cellheight)
   Next
End Sub

Sub btnNumKeyPad_click
   Dim tempBtn As Button=Sender
   Dim tempTag As Int=tempBtn.Tag
   aLabel.Text=aLabel.text & tempTag
End Sub

Sub btnNumKeyPad_longClick
   ' set long press on 0 to clear the label
   ' set long press on other numbers to clear the label and set its text to the chosen number
   ' you can, of course handle this event the way you want.  
Dim tempBtn As Button=Sender
   Dim tempTag As Int=tempBtn.Tag
   If tempTag=0 Then
     aLabel.Text=""
   else
     aLabel.Text=tempTag
   end if
 
Upvote 0
Back
Top