Android Question Button_Click event on a CustomDialog

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

Is there any way to add buttons to a CustomDialog and make them update a label on the custom dialog.

I want a real numpad, not the NumberDialog. And no, I don't want to use the Numpad in Android because its so bad on some devices.

I short, i want to make buttons on a CustomDialog do stuff. Is that possible?
 

TheMightySwe

Active Member
Licensed User
Longtime User
OK, I tried that and the event didn't fire, i'll have a look in the code if there is a spelling error or something like that.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
I have the code in "Main", The Buttons are dimmed in Globals, And i put the buttons on a panel that a send in to the BetterDialog, The "YourButton_Click" is also in main.

And the Event does not trigger when i click the button. What can be wrong?

It's probablly something really stupid, but it's hard to find.
 
Upvote 0

TheMightySwe

Active Member
Licensed User
Longtime User
Not all, but the parts that includes this. It's really big.

In Process_Globals

B4X:
    Type NumericAnswer(Cancelled As Boolean, Value As Double)

In Globals

B4X:
    Dim CoverScreen As Panel
    Dim Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9 As Button
    Dim ButtonComma, ButtonBack As Button
    Dim ValueLabel As Label

In Activity_Create

B4X:
    Dim NumberDialogAnswer As NumericAnswer
    Dim NumberDialogValue As Double
    NumberDialogAnswer = NumericDialog
   
    If NumberDialogAnswer.Cancelled = True Then
        Return
    Else
        NumberDialogValue = NumberDialogAnswer.Value
    End If

The Sub

B4X:
Sub NumericDialog As NumericAnswer

    Dim ReturnValue As NumericAnswer
    ReturnValue.Initialize
   
    Dim ButtonWidth, ButtonHeight, NumPadWidth, NumPadHeight As Int

    CoverScreen.Initialize("CoverScreen")
    CoverScreen.Color = Colors.ARGB(200,29,25,35)

    If 100%x < 320dip Then
        NumPadWidth = 100%x
        ButtonWidth = (100%x - 20dip) / 3
    Else
        NumPadWidth = (100dip * 3) + (5dip * 4)
        ButtonWidth = 100dip
    End If

    If 100%y < 365dip Then
        NumPadHeight = 100%y
        ButtonHeight = (100%y - 115dip) / 5
    Else
        NumPadHeight = (60dip * 5) + (5dip * 6)
        ButtonHeight = 60dip
    End If

    Dim NumericButtonDialog As BetterDialogs
   
    ValueLabel.Initialize("ValueLabel")
    CoverScreen.AddView(ValueLabel,5dip, 5dip, (3 * ButtonWidth) + (2 * 5dip) ,ButtonHeight)
    ValueLabel.Color = Colors.White
    ValueLabel.Gravity = Bit.OR(Gravity.RIGHT, Gravity.CENTER_VERTICAL)
    ValueLabel.Typeface = DroidSansMono
    ValueLabel.Text = ""
   
    ' Första raden

    Button7.Initialize("NumpadNumber7")
    CoverScreen.AddView(Button7, 5dip, (5dip*2) + ButtonHeight, ButtonWidth ,ButtonHeight)
    Button7.TextColor = Colors.Black
    Button7.Text = "7"
    Button7.Gravity = Gravity.CENTER
    Button7.Typeface = DroidSansBold
    Button7.Background = Graphics.NumpadButton(Button7,Colors.RGB(230,228,234))
   
    Button8.Initialize("NumpadNumber8")
    CoverScreen.AddView(Button8, (5dip*2) + ButtonWidth, (5dip*2) + ButtonHeight, ButtonWidth ,ButtonHeight)
    Button8.TextColor = Colors.Black
    Button8.Text = "8"
    Button8.Gravity = Gravity.CENTER
    Button8.Typeface = DroidSansBold
    Button8.Background = Graphics.NumpadButton(Button8,Colors.RGB(230,228,234))

    Button9.Initialize("NumpadNumber9")
    CoverScreen.AddView(Button9, (5dip*3) + (ButtonWidth*2), (5dip*2) + ButtonHeight, ButtonWidth ,ButtonHeight)
    Button9.Color = Colors.LightGray
    Button9.TextColor = Colors.Black
    Button9.Text = "9"
    Button9.Gravity = Gravity.CENTER
    Button9.Typeface = DroidSansBold
    Button9.Background = Graphics.NumpadButton(Button9,Colors.RGB(230,228,234))

    ' Andra raden
   
    Button4.Initialize("NumpadNumber4")
    CoverScreen.AddView(Button4, 5dip, (5dip*3) + (ButtonHeight*2), ButtonWidth ,ButtonHeight)
    Button4.TextColor = Colors.Black
    Button4.Text = "4"
    Button4.Gravity = Gravity.CENTER
    Button4.Typeface = DroidSansBold
    Button4.Background = Graphics.NumpadButton(Button4,Colors.RGB(230,228,234))
   
    Button5.Initialize("NumpadNumber5")
    CoverScreen.AddView(Button5, (5dip*2) + ButtonWidth, (5dip*3) + (ButtonHeight*2), ButtonWidth ,ButtonHeight)
    Button5.TextColor = Colors.Black
    Button5.Text = "5"
    Button5.Gravity = Gravity.CENTER
    Button5.Typeface = DroidSansBold
    Button5.Background = Graphics.NumpadButton(Button5,Colors.RGB(230,228,234))

    Button6.Initialize("NumpadNumber6")
    CoverScreen.AddView(Button6, (5dip*3) + (ButtonWidth*2), (5dip*3) + (ButtonHeight*2), ButtonWidth ,ButtonHeight)
    Button6.TextColor = Colors.Black
    Button6.Text = "6"
    Button6.Gravity = Gravity.CENTER
    Button6.Typeface = DroidSansBold
    Button6.Background = Graphics.NumpadButton(Button6,Colors.RGB(230,228,234))

    ' Tredje raden
   
    Button1.Initialize("NumpadNumber1")
    CoverScreen.AddView(Button1, 5dip, (5dip*4) + (ButtonHeight*3), ButtonWidth ,ButtonHeight)
    Button1.TextColor = Colors.Black
    Button1.Text = "1"
    Button1.Gravity = Gravity.CENTER
    Button1.Typeface = DroidSansBold
    Button1.Background = Graphics.NumpadButton(Button1,Colors.RGB(230,228,234))
   
    Button2.Initialize("NumpadNumber2")
    CoverScreen.AddView(Button2, (5dip*2) + ButtonWidth, (5dip*4) + (ButtonHeight*3), ButtonWidth ,ButtonHeight)
    Button2.TextColor = Colors.Black
    Button2.Text = "2"
    Button2.Gravity = Gravity.CENTER
    Button2.Typeface = DroidSansBold
    Button2.Background = Graphics.NumpadButton(Button2,Colors.RGB(230,228,234))

    Button3.Initialize("NumpadNumber3")
    CoverScreen.AddView(Button3, (5dip*3) + (ButtonWidth*2), (5dip*4) + (ButtonHeight*3), ButtonWidth ,ButtonHeight)
    Button3.TextColor = Colors.Black
    Button3.Text = "3"
    Button3.Gravity = Gravity.CENTER
    Button3.Typeface = DroidSansBold
    Button3.Background = Graphics.NumpadButton(Button1,Colors.RGB(230,228,234))

    ' Fjärde raden
   
    Button0.Initialize("NumpadNumber0")
    CoverScreen.AddView(Button0, 5dip, (5dip*5) + (ButtonHeight*4), ButtonWidth ,ButtonHeight)
    Button0.TextColor = Colors.Black
    Button0.Text = "0"
    Button0.Gravity = Gravity.CENTER
    Button0.Typeface = DroidSansBold
    Button0.Background = Graphics.NumpadButton(Button0,Colors.RGB(230,228,234))
   
    ButtonComma.Initialize("NumpadComma")
    CoverScreen.AddView(ButtonComma, (5dip*2) + ButtonWidth, (5dip*5) + (ButtonHeight*4), ButtonWidth ,ButtonHeight)
    ButtonComma.TextColor = Colors.Black
    ButtonComma.Text = ","
    ButtonComma.Gravity = Gravity.CENTER
    ButtonComma.Typeface = DroidSansBold
    ButtonComma.Background = Graphics.NumpadButton(ButtonComma,Colors.RGB(230,228,234))

    ButtonBack.Initialize("NumpadBack")
    CoverScreen.AddView(ButtonBack, (5dip*3) + (ButtonWidth*2), (5dip*5) + (ButtonHeight*4), ButtonWidth ,ButtonHeight)
    ButtonBack.TextColor = Colors.Black
    ButtonBack.Text = "<-"
    ButtonBack.Gravity = Gravity.CENTER
    ButtonBack.Typeface = DroidSansBold
    ButtonBack.Background = Graphics.NumpadButton(ButtonBack,Colors.Yellow)

    Dim Response As Int

    Response = NumericButtonDialog.CustomDialog("I want this numpad to WORK!",0,0,CoverScreen,NumPadWidth, NumPadHeight, 5dip, Dialogs.Dialog_Icon,"OK","Cancel","",False,"Numpad")
   
    ReturnValue.Value = ValueLabel.Text
   
    Select Response
   
        Case DialogResponse.POSITIVE :
       
            ReturnValue.Cancelled = False
       
        Case DialogResponse.CANCEL :
       
            ReturnValue.Cancelled = True
       
        Case DialogResponse.NEGATIVE :
   
            ReturnValue.Cancelled = False

    End Select

    Return ReturnValue
   
End Sub

Make RoundButtons

B4X:
Sub NumpadButton(TargetButton As Button, Color As Int) As StateListDrawable

    Dim Default, Disabled, Pressed As BitmapDrawable

    Default.Initialize(NumpadButtonMaker(TargetButton, Color,0))
    Disabled.Initialize(NumpadButtonMaker(TargetButton, Color,1))
    Pressed.Initialize(NumpadButtonMaker(TargetButton, Color,2))

    Dim Background_StateListDrawable As StateListDrawable
    Background_StateListDrawable.Initialize
   
    Background_StateListDrawable.AddState(Background_StateListDrawable.State_Disabled, Disabled)
    Background_StateListDrawable.AddState(Background_StateListDrawable.State_Pressed, Pressed)
    Background_StateListDrawable.AddCatchAllState(Default)
   
    Return Background_StateListDrawable

End Sub


Sub NumpadButtonMaker(TargetButton As Button, Color As Int, State As Int) As Bitmap

    Dim Red,Green,Blue,Alpha As Int
   
        Alpha = Bit.UnsignedShiftRight(Bit.AND(Color, 0xff000000), 24)
        Red = Bit.UnsignedShiftRight(Bit.AND(Color, 0xff0000), 16)
        Green  = Bit.UnsignedShiftRight(Bit.AND(Color, 0xff00), 8)
        Blue = Bit.AND(Color, 0xff)

    Dim Background As Bitmap
    Background.InitializeMutable(TargetButton.Width, TargetButton.Height)
   
    Dim Area As Rect
   
    ' Dim ButtonEffects As RSImageEffects

    Dim Pen As Canvas
    Pen.Initialize2(Background)
   
    Select State
   
    Case 0:
   
        Dim Shadow As GradientDrawable
        Dim GradColors(2) As Int
        GradColors(0) = Colors.ARGB(255,25,25,25)
        GradColors(1) = Colors.ARGB(255,0,0,0)
        Shadow.Initialize("TOP_BOTTOM",GradColors)
        Area.Initialize(3,3,TargetButton.Width - 3, TargetButton.Height - 3)
        Shadow.CornerRadius = (1%x + 1%y) / 2
        Pen.DrawDrawable(Shadow,Area)

        Dim RealButton As GradientDrawable
        Dim GradColors(2) As Int
        GradColors(0) = Colors.ARGB(255,Red,Green,Blue)
        GradColors(1) = Colors.ARGB(220,Red,Green,Blue)
        RealButton.Initialize("TOP_BOTTOM",GradColors)
        RealButton.CornerRadius = (1%x + 1%y) / 2
        Area.Initialize(0,0,TargetButton.Width - 6, TargetButton.Height - 6)
        Pen.DrawDrawable(RealButton,Area)
       
    Case 1:
   
        Dim Shadow As GradientDrawable
        Dim GradColors(2) As Int
        GradColors(0) = Colors.ARGB(255,25,25,25)
        GradColors(1) = Colors.ARGB(255,0,0,0)
        Shadow.Initialize("TOP_BOTTOM",GradColors)
        Area.Initialize(3,3,TargetButton.Width - 3, TargetButton.Height - 3)
        Shadow.CornerRadius = (1%x + 1%y) / 2
        Pen.DrawDrawable(Shadow,Area)

        Dim RealButton As GradientDrawable
        Dim GradColors(3) As Int
        GradColors(0) = Colors.ARGB(255,Red,Green,Blue)
        GradColors(1) = Colors.ARGB(220,Red,Green,Blue)
        GradColors(2) = Colors.ARGB(255,Red,Green,Blue)
        RealButton.Initialize("TR_BL",GradColors)
        RealButton.CornerRadius = (1%x + 1%y) / 2
        Area.Initialize(0,0,TargetButton.Width - 6, TargetButton.Height - 6)
        Pen.DrawDrawable(RealButton,Area)

    Case 2:

        Dim RealButton As GradientDrawable
        Dim GradColors(2) As Int
        GradColors(0) = Colors.ARGB(80,Red,Green,Blue)
        GradColors(1) = Colors.ARGB(60,Red,Green,Blue)
        RealButton.Initialize("TOP_BOTTOM",GradColors)
        RealButton.CornerRadius = (1%x + 1%y) / 2
        Area.Initialize(0,0,TargetButton.Width - 6, TargetButton.Height - 6)
        Pen.DrawDrawable(RealButton,Area)
   
    End Select
       
    Return Background

End Sub

I think that is all you need...

And this is what don't work

B4X:
Sub NumpadNumber7_Click

    Msgbox("7","Numeric Test Input")
   
End Sub
 
Upvote 0
Top