Android Question Return view name (name of pointer)

AndOrNot

Well-Known Member
Licensed User
Hi all, i've different view in an activity, that i had initialize, for example
B4X:
dim lbl1 as label
dim lbl2 as label
dim txt1 as edittext
Is there a way to get the name of pointer?
For example, i want to get that first label'name is "lbl1", second is "lbl2", ecc..
But i can't use tag, because i already use it..
Thx all, best regards
 

AndOrNot

Well-Known Member
Licensed User
You dont need a name!! You just need a living reference to the object.

In click event you can recast the label to a new object using the SENDER

B4X:
dim lbl as Label = sender
log(lbl.Text)
log(lbl.tag)
What are you trying to implement?
I want to use the name for implement the translate of app. I want to put in res file the string translated with the name of view, and in loop like this:
B4X:
For each v as view in activity.getAllRecursiveViews
if v is label then
dim c as label
c = v
c.text = ResourceStrings.Get("c.name") 'But i'm not able
end if
I think is the easiest solution to read, when you set all label text based on values string
 
Last edited:

LucaMs

Expert
Licensed User
But i can't use tag, because i already use it..
Tags can hold objects. You could use a Map.

Dim mapViewData As Map
mapViewData.Initialize
Dim OtherTagData As ...
mapViewData.Put("lblCustomer", OtherTagData)
lblCustomer.Tag = mapViewData

B4X:
For each v as view in activity.getAllRecursiveViews
if v is label then
dim c as label
c = v
Dim mViewData As Map = c.Tag
Dim ViewName As String = mViewData.GetKeyAt(0)
c.text = ResourceStrings.Get(ViewName) 'But i'm not able
end if
 

AndOrNot

Well-Known Member
Licensed User
Tags can hold objects. You could use a Map.

Dim mapViewData As Map
mapViewData.Initialize
Dim OtherTagData As ...
mapViewData.Put("lblCustomer", OtherTagData)
lblCustomer.Tag = mapViewData

B4X:
For each v as view in activity.getAllRecursiveViews
if v is label then
dim c as label
c = v
Dim mViewData As Map = c.Tag
Dim ViewName As String = mViewData.GetKeyAt(0)
c.text = ResourceStrings.Get(ViewName) 'But i'm not able
end if
Thanks, it is a solution that i don't think.. but to return the name is impossible? Without set it into string variable, map and other..
 
Top