programmatically name views

Aysic4Bandroid

Member
Licensed User
Longtime User
hi,

i have a sub that is called to add a panel of child views when a button is clicked so there can be any number of these panels in the activity at any time. I want to give each panel a unique name as its created so i can reference it when in the code. The sub creates the panel with a name, 'pnlrow' however each time it is called it obviously gives each new panel the same name how can i change this at the time of dimming it??

i.e. dim pnlrow & "_" & i As Panel

so each panel name is appended with an underscore and incrementing integer?

or, since i am giving each panel a unique tag attribute how can i reference the panel by its tag? Like the DOM's getElementById(id) ... getViewNameByTag(tag)
 

kickaha

Well-Known Member
Licensed User
Longtime User
Use a map, you can store the name as the key, and the Panel as the value.

You can the use Get(panelname) to get the panel.
 
Upvote 0

stefanobusetto

Active Member
Licensed User
Longtime User
if panels are added to the activity

For i = 0 To Activity.NumberOfViews - 1
Dim v As View
v = Activity.GetView(i)

If v Is Panel Then
Dim p As Panel
p = v

If p.Tag = ? Then
p is your panel
End If
End If

Next
 
Upvote 0

Aysic4Bandroid

Member
Licensed User
Longtime User
yes i try that (stefanobusetto) since i'm using the tags anyway. i thought there was a hidden view memeber that id missed. - Didnt for a minute think when planning this that it wasnt possible to programmatically create unique view names. b4a does some great stuff and then just when you think you've got it 'pegged' it throws a suprising spanner in the works - coming from the PHP world i guess i have to be patient and grow with b4a till its as mature as PHP
 
Upvote 0

Aysic4Bandroid

Member
Licensed User
Longtime User
thanks kickaha, have not used Maps yet (still as nooob) but since im using tags already guess ill go with stefanobusetto solution

many thanks for taking time to reply

cheers
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…