Yayou49 Active Member Licensed User Sep 7, 2018 #1 Hi, I add one views in a layout by designer or by code. Let set as exemple, 1 buttons (can be also a Panel view or else). I gave it a name: BT1. Code: Dim BT1 as Button bt1.initialize("BT1") Activity.AddView(BT1, 10%x, 20%y, 10%x, 10%x ) Using the code bellow, I can retrieve my button, but my problem is: How to retrieve the name (BT1) or at least a unique ID for this button ??? My purpose is to get a unique identifier for my view each time the apk is launched (identifer must be the same each time the apk is launched) Code: For Each v As View In Activity.GetAllViewsRecursive log(v.????) Next Too involved by my project, I can't find how. If solution is quite basic, sorry in advance !!!!.....
Hi, I add one views in a layout by designer or by code. Let set as exemple, 1 buttons (can be also a Panel view or else). I gave it a name: BT1. Code: Dim BT1 as Button bt1.initialize("BT1") Activity.AddView(BT1, 10%x, 20%y, 10%x, 10%x ) Using the code bellow, I can retrieve my button, but my problem is: How to retrieve the name (BT1) or at least a unique ID for this button ??? My purpose is to get a unique identifier for my view each time the apk is launched (identifer must be the same each time the apk is launched) Code: For Each v As View In Activity.GetAllViewsRecursive log(v.????) Next Too involved by my project, I can't find how. If solution is quite basic, sorry in advance !!!!.....
npsonic Active Member Licensed User Sep 7, 2018 #2 Use tags Code: Dim BT1 as Button bt1.initialize("BT1") Activity.AddView(BT1, 10%x, 20%y, 10%x, 10%x ) bt1.Tag = "BT1" Code: For Each v As View In Activity.GetAllViewsRecursive If v.Tag <> Null Then Select v.Tag Case "BT1" Log("BT1") Case "BT2" Log("BT2") End Select End If Next Upvote 0
Use tags Code: Dim BT1 as Button bt1.initialize("BT1") Activity.AddView(BT1, 10%x, 20%y, 10%x, 10%x ) bt1.Tag = "BT1" Code: For Each v As View In Activity.GetAllViewsRecursive If v.Tag <> Null Then Select v.Tag Case "BT1" Log("BT1") Case "BT2" Log("BT2") End Select End If Next
Yayou49 Active Member Licensed User Sep 7, 2018 #3 npsonic said: Use tags Click to expand... Not possible in my case. my functionality is based on layout created by other people (with or without tags). That's why I need a unique "app view" identifier... Thanks anyway Upvote 0
npsonic said: Use tags Click to expand... Not possible in my case. my functionality is based on layout created by other people (with or without tags). That's why I need a unique "app view" identifier... Thanks anyway
Semen Matusovskiy Well-Known Member Licensed User Sep 7, 2018 #4 Tag is alone correct way. Really it's not simple string or integer value. Tag is object. This means that should be an agreement inside the team. A tag will be a list, first element will be used by Alex, second by Nick etc. Last edited: Sep 7, 2018 Upvote 0
Tag is alone correct way. Really it's not simple string or integer value. Tag is object. This means that should be an agreement inside the team. A tag will be a list, first element will be used by Alex, second by Nick etc.
Cableguy Expert Licensed User Longtime User Sep 7, 2018 #5 There might be a way…. Not tested when you do "log(btn1) the log will show a unique value that is a reference to that view in that activity. The main problem is, you can reuse any view without ever destroying it, !but!, this is the problem, if I am not mistaken, each time you change a view's parent, that "unique" reference changes too. Even when you "clone" a view, there is no assurance it will stay the same … SO, in conclution, you will need to do your own testing! Upvote 0
There might be a way…. Not tested when you do "log(btn1) the log will show a unique value that is a reference to that view in that activity. The main problem is, you can reuse any view without ever destroying it, !but!, this is the problem, if I am not mistaken, each time you change a view's parent, that "unique" reference changes too. Even when you "clone" a view, there is no assurance it will stay the same … SO, in conclution, you will need to do your own testing!
Erel B4X founder Staff member Licensed User Longtime User Sep 9, 2018 #6 You can use a Map to "attach" any data you like to the views. Code: ExtraData.Put(Button12, 123123123) Dim id As Int = ExtraData.Get(Button12) Upvote 0
You can use a Map to "attach" any data you like to the views. Code: ExtraData.Put(Button12, 123123123) Dim id As Int = ExtraData.Get(Button12)
Yayou49 Active Member Licensed User Sep 9, 2018 #7 Still not possible in my case .... Maybe you will understand better with the new library I've uploaded in the forum : https://www.b4x.com/android/forum/t...s-positions-while-running-live-the-apk.97040/ Upvote 0
Still not possible in my case .... Maybe you will understand better with the new library I've uploaded in the forum : https://www.b4x.com/android/forum/t...s-positions-while-running-live-the-apk.97040/
npsonic Active Member Licensed User Sep 9, 2018 #8 It might be that I don't understand what you exactly are trying to do, but why couldn't you just give some unique tag for each view and then save extra data about that view with the identifier to map. Tag is a key in map and value can be anything you want to store about that particular view. Upvote 0
It might be that I don't understand what you exactly are trying to do, but why couldn't you just give some unique tag for each view and then save extra data about that view with the identifier to map. Tag is a key in map and value can be anything you want to store about that particular view.