Click event mapped to many panels

CharlesIPTI

Active Member
Licensed User
Longtime User
Sample attached. Code created view (panel) with View(Panel) inside of it

no formal designation for parent child just manual placement via code.

There's 7 little panels inside of the main panel and each houses 8 labels.

The Event upon initializing these 7 panels are all set to the same method name


Yet the event only "reports" that the last panel was clicked despite which one you really clicked..

I.E. you can click any of the panels and get the toast message however it claims that the sender was the last placed panel not the one clicked

So what did the noob do this time please and thank you
 

Attachments

  • 5_3_2012SenderProblems.zip
    17.1 KB · Views: 155

klaus

Expert
Licensed User
Longtime User
You must add a Dim for each panAlpha.
B4X:
Dim panAlpha As Panel
panAlpha.Initialize("panAlphaEvent")
The same for all the other views before the Initialize.
The Dim is necessary to initiate each time a new instance of the view.

Best regards.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Smaller App to Test

Maybe I'm having problems with the Layout file being present in the project I'm not sure but your recommendation it still isn't working.

Perhaps the Base Panel Just doesn't get any event associated with it..
and only the sub panels that sit on it actually get click events .

That's the direction I was testing until I hit this ugly panel / layout
which comes first problem


Thank you for looking at it
 

Attachments

  • Re Test Panel Events Shared.zip
    6.8 KB · Views: 143
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I couldn't see the panels correctly on my 5" screen, but this code works without a problem:

B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim panMain As Panel
panMain.Initialize("panEvent") 
panMain.Color = Colors.White
panMain.Tag = "Main Base Big Panel"
Dim panSubOne As Panel
panSubOne.Initialize("panEvent")
panSubOne.Tag = "little SubOne Panel"
panMain.Color = Colors.Red
Dim panSubTwo As Panel
panSubTwo.Initialize("panEvent")
panSubTwo.Tag = "little SubTwo Panel"
panSubTwo.Color = Colors.Blue
Dim aw As Int,ah As Int 
aw=Activity.Width 
ah=Activity.Height 
Activity.AddView(panMain,0,0,aw,ah)
panMain.AddView(panSubOne,0,0,aw,ah/2)
panMain.AddView(panSubTwo,0,ah/2,aw,ah/2)
ToastMessageShow("Methods initialized.", False)
End Sub

You also had a small error with panels' colors (probably you forgot to change the letters after pasting), here:
B4X:
Dim panSubOne As Panel
panSubOne.Initialize("panEvent")
panSubOne.Tag = "little SubOne Panel"
panMain.Color = Colors.Red
Dim panSubTwo As Panel
panSubTwo.Initialize("panEvent")
panSubTwo.Tag = "little SubTwo Panel"
panMain.Color = Colors.Blue

I think you wanted to write:
B4X:
Dim panSubOne As Panel
panSubOne.Initialize("panEvent")
panSubOne.Tag = "little SubOne Panel"
panSubOne.Color = Colors.Red
Dim panSubTwo As Panel
panSubTwo.Initialize("panEvent")
panSubTwo.Tag = "little SubTwo Panel"
panSubTwo.Color = Colors.Blue
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As you can see in the code of mc73, the problem is in these lines:
B4X:
panMain.AddView(panSubOne,266dip,300dip,150dip,100dip)
panMain.AddView(panSubTwo,416dip,300dip,150dip,100dip)
You are reasoning in global dimensions. But the child object positions refer to their parent object and not to the screen.
If you want a child panel in the top left corner of the parent panel the x and y coordinates of the child panel must be ZERO and not the parent panel coordinates.
The two lines become:
B4X:
panMain.AddView(panSubOne,0,0,150dip,100dip)
panMain.AddView(panSubTwo,150dip,0,150dip,100dip)
The colors are also already mentioned.

Best regards.
 

Attachments

  • TEST 5 3 12 New.zip
    5.8 KB · Views: 146
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
A Display Oddity & Thank you

Firstly thank you both for your corrections, again I appreciate it and apologize for the little copy paste mistakes... :signOops:

So As I add (via code) the panels to another panel --panMain.AddView(panSubOne,

I've got the visual designer and its properties list stuck in my mind,
is this line of code actually designating the subpanel as a child of the Main Panel?
Given the description of the coordinates for placing these panels I assume the answer is yes...

I attached my cleaned up version and it functions as desired but I noticed that the Big Main panel is not displayed when I correctly have the smaller sub panels sitting on top of it. I am placing the real production versions with a bit of spacing so you can see separator lines between the sub panels which actually is the Main panel behind them so I do want the main panel to be visible.

I tried this but it did not help ::
panMain.SendToBack
panSubOne.BringToFront()
panSubTwo.BringToFront()

Lastly I tested it and it doesn't seem to matter if I add the main panel to the activity before or after I add the sub panels to the main panel. Any thoughts ?
 

Attachments

  • Reviewed PanelLayering 5 4 2012.zip
    5.8 KB · Views: 146
Upvote 0

klaus

Expert
Licensed User
Longtime User
I don't really understand what your problem is.
In your code you have:
B4X:
Activity.AddView(panMain,266dip, 300dip, 800dip, 300dip)

panMain.AddView(panSubOne,0,0,400dip,100dip)
panMain.AddView means that you add panSubOne onto panMain therefor panSubOne is a child object of panMain. You don't need any SendToBack and BrihgToFront.
If you set panMain.Visible = False then panMain will be hidden with all its child views on it.

If you wanted panSubOne not beeing a child view of panMain then you should add it to the Activity but with screen coordinates.
B4X:
Activity.AddView(panSubOne,266dip, 300dip, 400dip, 100dip)
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Correction Problem Description

Thank you

The problem is that the parent doesn't display at all.

The click functionality is present for ALL panels, but the main panel doesn't show.
If I add an event to the parent it will invoke that click when I select the parent but I only added that to make sure the parent was actually there since it doesn't display.

I have removed the event for the parent, but I mention it just to assist describing this concern.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I don't know on what device you test your program, but in the Emulator panMain is displayed.
I don't have a tablet yet.

Best Regards.
 

Attachments

  • Reviewed PanelLayering 5 4 2012_1.zip
    5.8 KB · Views: 161
  • Panels.jpg
    Panels.jpg
    27 KB · Views: 184
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Thank You

I don't recall what My error was Klaus
but I have them all displaying and in my real app all is fine for this little portion thank you all for your help.

The Production app has a big panel in the back with no click event .
three rows of panels first two rows have two panels last row three panels.
All these little panels have a click event and 8 labels in them. All are responding correctly, Thank you I am testing on Samsung Galaxy 10.1
 
Upvote 0
Top