Android Question Label Tag property

elitevenkat

Active Member
Licensed User
Longtime User
I am trying to assign a map data type to a label tag property. In the label click event, creating a map type. however the label.tag property is shown as an empty string.

B4X:
'in jobdone i am initialising a mapvariable and moving data 

Dim mTable As Map
                    mTable.Initialize
                       
                    mTable.Put(0,row(3))   ' occupied / vacant
                    mTable.Put(1,row(7))   ' unsettled
                    mTable.Put(2,row(11))  ' hold   
                    mTable.Put(3,row(0))   ' tablepckey
                    mTable.Put(4,row(4))   ' captain name
                    mTable.Put(5,row(5))   ' waiter name
                    mTable.Put(6,row(6))   ' pax 
                    mTable.Put(7,row(9))   ' captain key
                    mTable.Put(8,row(10))   ' waiter key
                   
   
                    lblTable.Text=row(1)
                    lblTable.Tag=mTable
                   
Log("tag size " & mTable.Size)    ' result 9
Log("Tag " & lblTable.Tag) ' result {0=false, 1=false, 2=false, 3=335, 4=, 5=, 6=1, 7=15, 8=25}


Sub lblTable_Click
    Dim l As Label
    l=Sender
         
    Log("text "  & l.Text)  ' result 14B
   
    Log("tag "  & l.Tag)     ' result tag - no value     

    Dim m As Map
    m=l.Tag                  ' HERE I GET ERROR


the same kind of code works fine in a B4J project.

can someone help me ?

error thrown in b4a

java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at newkot.com.posandtables._lbltable_click(posandtables.java:826)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11159)
at android.view.View$PerformClick.run(View.java:23752)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
 

LucaMs

Expert
Licensed User
Longtime User
Most likely the label clicked is not the one that contains that tag.

Write also Log(lblTable.Text) after the other logs.

[Suggestion: use constants for the index of the map, like

Public Const XXX_OCCUPIED As Int = 1
Public Const XXX_UNSETTLED As Int = 2
Public Const XXX_HOLD As Int = 3

replacing XXX with something meaningful
]
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
Most likely the label clicked is not the one that contains that tag.

Write also Log(lblTable.Text) after the other logs.

[Suggestion: use constants for the index of the map, like

Public Const XXX_OCCUPIED As Int = 1
Public Const XXX_UNSETTLED As Int = 2
Public Const XXX_HOLD As Int = 3

replacing XXX with something meaningful
]
Using contents suggestion taken well. In fact the l.text value is displaying correctly. The sub click event is correct.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In fact the l.text value is displaying correctly.
Write also Log(lblTable.Text) after the other logs.
Are you sure?
I meant: insert a log for the label text when you fill it:
Log("tag size " & mTable.Size) ' result 9
Log("Tag " & lblTable.Tag) ' result {0=false, 1=false, 2=false, 3=335, 4=, 5=, 6=1, 7=15, 8=25}

not only in the label click routine.

I'm pretty sure that they are two different labels.
 
Upvote 0
Top