Program doesn't read Sub

philippek

Member
Licensed User
Longtime User
Hi Guys,

I have a really strange thing going on here.
I have a panel with a button and listview on it, if you press the back button I want the panel to disappear, that works.
But I also want if you press the button the panel also disapears. But that doesn't work, and the strang thing is the program doesn't read the entire sub, because I put a msgbox in it, but the msgbox also doesn't appear.
Here is my code (only the relevant part:, I renamed the views to make it more clear).
ButtonShowPanel is made with the designer, the others are made in the code.
B4X:
Sub Globals
dim Panel1 as panel
dim Listview as listview
dim buttonExitPanel as button
dim buttonShowPanel as button
dim IO as int
end sub

B4X:
Sub activity_keypress (KeyCode As Int) As Boolean   
   If keycode = KeyCodes.KEYCODE_BACK Then
      If IO = 1 Then 
         panel1.RemoveView
         listview1.RemoveView
         buttonExitPanel.RemoveView
         IO = 0
         Return True
               end if
end if
end sub

B4X:
Sub ButtonShowPanel_Click
   IO = 1
   Panel1.Initialize("")
   Listview1.Initialize("Listview1")
   activity.AddView(Panel1,  0, 0, 100%x, 100%y)
   Listview1.Visible = True
   Panel1.Visible = True
   Listview1.Color = Colors.black
   Panel1.Visible = True
   Panel1.Color = Colors.black
   Panel1.AddView(Listview1, 0, 50, 100%x, 100%y-40dip)
   ButtonExitPanel.Initialize("")
   Panel1.AddView(ButtonExitPanel,0,0,110,50)
   ButtonExitPanel.Text = "Exit Smith"
   ButtonExitPanel.TextSize = 9
   ButtonExitPanel.Enabled = True 
   activity.Invalidate
End Sub

This is the sub that the program doesn't read:
B4X:
Sub ButtonExitPanel_Click
   Msgbox("Exit Test", "TEST")
   If IO = 1 Then 
      Panel1.RemoveView 
      listview1.RemoveView 
      ButtonExitPanel.RemoveView
      IO = 0
         
   End If

Thanks in advance!
Best Regards,
PhilippeK
PS Sorry for my bad English :sign0104:.
 
Last edited:

philippek

Member
Licensed User
Longtime User
Thanks for your reply!
This is not the only panel in my program, so for myself it's better to just remove the view, then just make in invisible.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You will have to keep in mind that removing views might render some Subs unreachable since there is (for example) no button to trigger it, that's why I was suggesting using panel visibility.
 
Upvote 0

philippek

Member
Licensed User
Longtime User
I Have tried it with visible = false, but same result: Back button made it dissapear but the button still doesn't work.
 
Upvote 0

bees

Member
Licensed User
Longtime User
You should Initialize the button with the name of the sub

B4X:
    ButtonExitPanel.Initialize("ButtonExitPanel")

Then it will fire the ButtonExitPanel_Click sub

HTH

Stephen
 
Upvote 0

philippek

Member
Licensed User
Longtime User
Bees Thank you so much. It solved my problem!
I always thought that for example button.Initialize("") will give the name thats for .initialize (in this case button). But I was wrong :sign0104:.

So thank you both for helping me out, I will give you some credit in the credits if the game will be released!
:sign0142:
 
Last edited:
Upvote 0
Top