Android Question Get all labels in a panel

Sanxion

Active Member
Licensed User
Longtime User
Guys

I am attempting to get all the labels in a panel in order to find a specifc one and then set the position of an image (ivResult) relative to that label - I am using the following:

For Each lbl As Label In pnl
Dim labelTag As String
labelTag = lbl.Tag
If labelTag = "MyText" Then
ivResult.Left = lbl.Left + 5dip
ivResult.Top = lbl.Top + 50dip
End If
Next

However, it is not working. The debugger just stops at the first line and exists - I suspect there is an error.

Any ideas?

Thank-you.
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Try

B4X:
For Each v As View In Activity.GetAllViewsRecursive
        If v Is Label Then
            Dim lb As  Label = v
         
        End If
Next
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
Try

B4X:
For Each v As View In Activity.GetAllViewsRecursive
        If v Is Label Then
            Dim lb As  Label = v
        
        End If
Next

Thanks. Does this not iterate through all the labels in the activity rather than just the one specific panel?

I ask because I have hundreds of labels and iterating through them all to find one would be ineficient would it not?
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
Sure, there is one !
You must replace pnl by the name of your Panel !

Yes I understand that Klaus. This is all the code:

For Each v As View In Activity

If v Is Panel Then

Dim PanelTag As String
Dim PanelID As Int
PanelTag = v.Tag

If PanelTag.StartsWith("Lesson") Then

PanelID = PanelTag.SubString2(6,PanelTag.Length)

If PanelID = VisiblePanelID + 1 Then

v.Visible = True

' Position the ivResult image so it is to the left of the text label

For Each w As View In v
If w Is Label Then
Dim labelTag As String
labelTag = w.Tag

If labelTag = "ArabicText" Then
ivResult.Left = v.Left - 130
ivResult.Top = 33%y '(Activity.Height - v.Height) / 2
End If

End If
Next

Else

Thiis the error:

For Each w As View In v
javac 1.8.0_65
src\b4a\MyFirstProgram\main.java:20145: error: incompatible types: ConcreteViewWrapper cannot be converted to IterableList
final anywheresoftware.b4a.BA.IterableList group6903 = _v;
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
When you post code you must use CODE tags !
upload_2015-12-16_20-38-0.png


In your case v is a View not a Panel.
Try this:
B4X:
Private pnl As Panel
pnl = v
For Each w As View In pnl
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
When you post code you must use CODE tags !
View attachment 39711

In your case v is a View not a Panel.
Try this:
B4X:
Private pnl As Panel
pnl = v
For Each w As View In pnl

Thank-you - that worked.

I did want to use the code tags but was not sure where the option was.

Now that is working. I want to ensure that ivResult always appears to the left of the label with a gao of approximately 1cm. Is my logic correct here?


B4X:
If labelTag = "ArabicText" Then
ivResult.Left = v.Left - 10
ivResult.Top = 33%y '(Activity.Height - v.Height) / 2
End If
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
1cm is not 10 !
You should at least use dip (density indepenant pixel) values.
But if you want 1cm you need to calculate it.
1dip is approximately 1/160 of an inch.
1dip is approximately 1/63 cm.
so 1cm is approximately 63dip.
Do you want the same gap on all devices, smartphones and tablets ?
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
1cm is not 10 !
You should at least use dip (density indepenant pixel) values.
But if you want 1cm you need to calculate it.
1dip is approximately 1/160 of an inch.
1dip is approximately 1/63 cm.
so 1cm is approximately 63dip.
Do you want the same gap on all devices, smartphones and tablets ?

Thank-you, that is useful to know.

Yes, a standard space for all devices.
 
Upvote 0
Top