When the user presses the menu key during my activity, I want to display a settings screen, but I can't use the preferences library because it does not support color options.
So, I have a layout designed with the abstract designer that has a panel at the top with a label and a button. I want to do something when the button is clicked. The code is not running when the button is clicked, which I can tell because the msgbox in that code does not pop up.
Can anyone tell me what is wrong with my code?
This code loads the first activity and when the user presses Menu, it displays the panel with the label and the button. However, clicking the button does nothing.
Doesn't MyButton.Initialize("ButtonFontSize") make Sub ButtonFontSize_Click the event handler? I don't understand why it is not firing.
So, I have a layout designed with the abstract designer that has a panel at the top with a label and a button. I want to do something when the button is clicked. The code is not running when the button is clicked, which I can tell because the msgbox in that code does not pop up.
Can anyone tell me what is wrong with my code?
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
'I don't think I even need these variables, but just in case
Dim ButtonFontSize As Button
Dim ScrollView1 As ScrollView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Set up Activity
StartAllOver
End Sub
Sub StartAllOver
'Msgbox("Starting ALL OVER","StartAllOver")
Activity.LoadLayout("MedsBarWithScrollView")
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_MENU Then
DisplayPreferencesActivity
End If
End Sub
Sub DisplayPreferencesActivity
Dim MyPanel As Panel
Dim MyLabel As Label
Dim MyButton As Button
Dim clrs(2) As Int
clrs(0) = Colors.RGB(32, 32, 32)
clrs(1) = Colors.RGB(64, 64, 64)
Dim gdButton As GradientDrawable
gdButton.Initialize("LEFT_RIGHT", clrs)
gdButton.CornerRadius = 5
clrs(0) = Colors.RGB(0, 0, 32)
clrs(1) = Colors.RGB(0, 0, 64)
Dim gdScrollView As GradientDrawable
gdScrollView.Initialize("TOP_BOTTOM", clrs)
Dim cdTransparent As ColorDrawable
cdTransparent.Initialize(Colors.ARGB(0,0,0,0), 0)
Activity.LoadLayout("PrefScroll")
MyPanel.Initialize("")
MyPanel.Background = cdTransparent
ScrollView1.Panel.AddView(MyPanel, 0, 0, ScrollView1.Panel.Width, 70)
ScrollView1.Background = gdScrollView
MyLabel.Initialize("")
MyLabel.Text = "Button font size"
MyLabel.TextSize = preferences.GetString("ButtonFontSize")
MyLabel.Background = cdTransparent
MyLabel.Color = Colors.Transparent
MyLabel.TextColor = Colors.White
MyLabel.Typeface = Typeface.DEFAULT_BOLD
MyPanel.AddView(MyLabel, 0, 5, ScrollView1.Panel.Width-30, 40)
MyButton.Initialize("ButtonFontSize")
MyButton.Text = ">"
MyButton.TextColor = Colors.White
MyButton.Typeface = Typeface.SANS_SERIF
MyButton.TextSize = 18
'MyButton.Background = cdTransparent
MyButton.Background = gdButton
'MyPanel.AddView(MyButton, ScrollView1.Panel.Width-30, 10, 30, 30)
MyPanel.AddView(MyButton, 0, 10, 30, 30)
End Sub
' This code is never getting fired
Sub ButtonFontSize_Click
Msgbox("ButtonFontSize_Click","ButtonFontSize_Click")
CreatePreferenceScreen
StartActivity(screen.CreateIntent)
'Activity.LoadLayout("Preferences")
End Sub
This code loads the first activity and when the user presses Menu, it displays the panel with the label and the button. However, clicking the button does nothing.
Doesn't MyButton.Initialize("ButtonFontSize") make Sub ButtonFontSize_Click the event handler? I don't understand why it is not firing.