Sender - tag does not exist

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I have the following code:

Sub View_Click
Dim Send As View
Dim Row As Int

Send=Sender
Row=Floor(Send.Tag/10)

but sometimes tag does not exist
(if I check Sender. parameters there is not tag inside)
how do I check if ".tag" exist before running the Send.Tag/10

Thanks
 

Cableguy

Expert
Licensed User
Longtime User
B4X:
if Send.Tag <>"" then Row=Floor(Send.Tag/10)
this only changes the ROW if the tag is not empty
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
According to my knowledge all types of views have the tag property.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
B4X:
if Send.Tag <>Null then Row=Floor(Send.Tag/10)
Then this should work, right?
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
I manage to get the bug again
here is screen shoot showing no "tag" inside
 

Attachments

  • pic1.JPG
    18.7 KB · Views: 245
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
To me it appears like this (see jpg).

Rolf
 

Attachments

  • SendTag.jpg
    16.4 KB · Views: 241
Upvote 0

agraham

Expert
Licensed User
Longtime User
It looks like the Activity (actually the ViewGroup that is the activity background on which the controls are placed which is what a BALayout is) is raising that event and it doesn't have a Tag property. I've no idea as to the mechanism by which it is raising that event.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
The bug is that when I press somewhere (can't figured it yet)
I get sender without a tag,
if I press the on the list, Iam getting tag
but you said there can't be such object without tab

how can I overcome such bug (I mean if sender return without tag)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
How have you assigned the View_Click sub to the views event? It must have been assigned or it wouldn't be calling the subroutine.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
did not understand
here is what I am doing, based of one of the list view examples code

....
Label3.Initialize("View")
Panel1.AddView(Label3,95dip,10dip,40dip,30dip)
Label3.Color=Colors.Black
Label3.TextColor = Colors.Green
Label3.Tag=i&"3"
....
ImageView1.Initialize("View")
ImageView1.Tag=i&"6"


Sub View_Click
Dim Send As View
Dim Row As Int

Send=Sender

If Send.Tag <> Null Then
Row=Floor(Send.Tag/10)
'DOING SOMETING WITH Row result'...
End If

End Sub
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User

You could check what type of view send contains first.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
I am a bit confused. What exactly is the error you are getting?

Does the Send.Tag property not exist? (That cannot really be possible.)
Or does the Send.Tag property have no value. That could of course be if you did not assign it any. Then Paulo's code would apply.

Rolf
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
My Point is that if you are manually initializing Labels:

B4X:
Label3.Initialize("View")

'and setting the tag

Label3.Tag=i&"3"
and manually initializing ImageViews

B4X:
ImageView1.Initialize("View")

'and setting the tag

ImageView1.Tag=i&"6"

Then these are the only views that should be calling the View_Click subroutine when touched, so either you have set an invalid tag (or not set one at all) or there is something else calling the View_Click subroutine.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just a thought, is it possible that you have something set up in the designer using View as an event sub without a tag?
 
Upvote 0

jkurant

Member
Licensed User
Longtime User
Shay, no one seems to understand your question. You are clearly setting the Tag property of the view that you added to what I don't recall now. I saw this in some code you posted in other notes on this thread.
I have the same problem. I have a layout I designed in the designer. That layout has a panel on it with three labels on the panel. I want that to be the template for repeating entries in a ScrollView. It each panel represents a reminder in my application. I want to list as many reminders as the user has created in this scrollview. I can create the panels and add them to the scroll view and I can hook up with _Click event and it fires when I click any panel, but it can't read the Tag property of the view in Sender. I get nothing. I need this to identify which entry in the list was clicked.
 
Upvote 0

jkurant

Member
Licensed User
Longtime User
Here is my code

The PanelReminder_Click sub fires, but p.Tag is always null or empty string.
In this language
B4X:
Dim p As Panel
instantiates a new object, right?


B4X:
Sub LoadReminders
   Dim InsideTabWidth As Int
   InsideTabWidth = Activity.Width - tabsInsideMargin*2 ' margin on the left and on the right
   Dim InsideTabHeight As Int
   InsideTabHeight = Activity.Height - 60dip
   Msgbox(InsideTabWidth, "InsideTabWidth")
   
   Dim p As Panel
   p.Initialize("PanelReminder")
   p.LoadLayout("ReminderListPanel")
   p.Tag = "1"
   svReminders.Panel.AddView(p, 0, 0, InsideTabWidth, 88dip)

   Dim p As Panel
   p.Initialize("PanelReminder")
   p.LoadLayout("ReminderListPanel")
   p.Tag = "2"
   svReminders.Panel.AddView(p, 0, 1*90dip, InsideTabWidth, 88dip)

End Sub

Sub PanelReminder_Click
   Dim p As Panel
   p = Sender
   Msgbox(p.Tag, "PanelReminder")
End Sub
 
Upvote 0

jkurant

Member
Licensed User
Longtime User
How to know which panel was clicked in a collection of like panels on a ScrollView

I coded it this way because it seems there is not a way to handle a click event for the ScrollView itself to find out what view contained within it was clicked, which makes sense.

With a listview, there is a click or item click you know which item was clicked. But with a ScrollView that contains many panels with the same content each, the ScrollView doesn't think of its contents as a list. It is just a bunch of controls. So, you have to capture an event on the control. And I have done that, because my msgbox pops up, but the tag property of Sender cast as a Panel is empty. My panel is initialized with the event name PanelReminder before it is added to the ScrollView and indeed the event fires. So I don't know why the tag property is empty.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…