Android Question how the experts manage to see / use this type of log command to solve the problems of preference dialog ?

AnandGupta

Expert
Licensed User
Longtime User
Recently I asked for few solutions on preference dialog and got them, thanks to Experts here.

Now my query is, how the experts manage to see / use this type of log command to solve the problems ?
for example,
B4X:
    For i = 0 To pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = pref.PrefItems.Get(i)
        If pi.ItemType = pref.TYPE_SHORTOPTIONS Then
            Dim c As B4XComboBox=pref.CustomListView1.GetPanel(i).GetView(1).Tag
            c.cmbBox.TextSize=18
        End If
    Next

all solutions are inside the loop,
B4X:
    For i = 0 To pref.PrefItems.Size - 1
...
...
    Next

But how they get to items like below which looks very complicated to me,
B4X:
pref.CustomListView1.GetPanel(i).GetView(0).GetView(0).TextColor = 0xFFA52A2A

I want to understand them so that I can also try to solve before putting them on the Forum.
 
Solution
Yes. Recursively. I do it manually, but you could write a Sub to do it.
You do have to check that the object has a tag.

B4X:
        Try
            If obj Is B4XView Then
                Log(index & TAB & GetType(obj) & TAB & GetType(obj.As(B4XView).Tag))
            Else
                Log(index & TAB & GetType(obj))
            End If
        Catch
            Log(LastException)
        End Try

William Lancee

Well-Known Member
Licensed User
Longtime User
If you access to the source code (which we do in this case, B4XLibs), you can see how the nodes are constructed and which piece goes where.
But I have also used the loop below to analyze the structure.

B4X:
    Dim nodeOfInterest As B4XView = Root  'as an example
    Dim nChildren As Int = nodeOfInterest.NumberOfViews
    For index = 0 To nChildren  - 1
        Dim obj As Object = Root.GetView(index)
        Try
            Log(index & TAB & GetType(obj))
        Catch
            Log(LastException)
        End Try
    Next
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
So repeatedly check for all child ? Okay.

But then .TAG is also used somewhere, so check that too ?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Yes. Recursively. I do it manually, but you could write a Sub to do it.
You do have to check that the object has a tag.

B4X:
        Try
            If obj Is B4XView Then
                Log(index & TAB & GetType(obj) & TAB & GetType(obj.As(B4XView).Tag))
            Else
                Log(index & TAB & GetType(obj))
            End If
        Catch
            Log(LastException)
        End Try
 
Upvote 0
Solution

William Lancee

Well-Known Member
Licensed User
Longtime User
An example of a recursive Sub
use on B4XView node: analyzeNode(Root) 'as an example

B4X:
'nodeDepth and indents are global
Private Sub analyzeNode(theNode As B4XView)
    nodeDepth = nodeDepth + 1
    Dim nChildren As Int = theNode.NumberOfViews
    For index = 0 To nChildren  - 1
        Dim obj As Object = theNode.GetView(index)
        Try
            If obj Is B4XView Then
                Log(indents.SubString2(0, nodeDepth - 1) & TAB & index & TAB & GetType(obj) & TAB & GetType(obj.As(B4XView).Tag))
                analyzeNode(obj)
            Else
                Log(index & TAB & GetType(obj))
            End If
        Catch
            Log(indents.SubString2(0, nodeDepth - 1) & TAB & LastException)
            nodeDepth = nodeDepth - 1
        End Try
    Next
    nodeDepth = nodeDepth - 1
End Sub
'ON LOG:
'    0    anywheresoftware.b4j.objects.PaneWrapper$ConcretePaneWrapper$NonResizePane    b4j.example.b4xfloattextfield
'        0    javafx.scene.control.TextField    java.lang.String
'            (ClassCastException) java.lang.ClassCastException: class javafx.scene.control.TextField cannot be cast To class javafx.scene.layout.Pane (javafx.scene.control.TextField Is in module javafx.controls of loader 'app'; javafx.scene.layout.Pane is in module javafx.graphics of loader 'app')
'        1    javafx.scene.image.ImageView    java.lang.String
'            (ClassCastException) java.lang.ClassCastException: class javafx.scene.image.ImageView cannot be cast To class javafx.scene.layout.Pane (javafx.scene.image.ImageView And javafx.scene.layout.Pane are in module javafx.graphics of loader 'app')
'        2    javafx.scene.control.Label    java.lang.String
'            (ClassCastException) java.lang.ClassCastException: class javafx.scene.control.Label cannot be cast To class javafx.scene.layout.Pane (javafx.scene.control.Label Is in module javafx.controls of loader 'app'; javafx.scene.layout.Pane is in module javafx.graphics of loader 'app')
'        3    javafx.scene.control.Label    java.lang.String
'            (ClassCastException) java.lang.ClassCastException: class javafx.scene.control.Label cannot be cast To class javafx.scene.layout.Pane (javafx.scene.control.Label Is in module javafx.controls of loader 'app'; javafx.scene.layout.Pane is in module javafx.graphics of loader 'app')
'    1    javafx.scene.control.Button    java.lang.String
'        (ClassCastException) java.lang.ClassCastException: class javafx.scene.control.Button cannot be cast To class javafx.scene.layout.Pane (javafx.scene.control.Button Is in module javafx.controls of loader 'app'; javafx.scene.layout.Pane is in module javafx.graphics of loader 'app')
 
Upvote 0

PaulMeuris

Active Member
Licensed User
You could use my B4XSources application to review the B4XPreferencesDialog.b4xlib file (PreferencesDialog.bas).
You can also use the GetAllViewsRecursive method:
B4X:
    For Each vw As B4XView In pnl.GetAllViewsRecursive
        Log(vw)
        Log("tag: " & vw.Tag)
    Next
Or for a CustomListView:
B4X:
    For i = 0 To clv1.Size -1
        For Each vw As B4XView In clv1.GetPanel(i).GetAllViewsRecursive
            Log(vw)
        Next
    Next
Each item in a CustomListView has a panel and in that panel you can add other views.
The AddTextItem method has a panel and a label.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Now my query is, how the experts manage to see / use this type of log command to solve the problems ?
for example,
Let us start by saying I am no expert here. I take a different approach. When I get stuck, here is what I do:
1. Unzip the B4XPreferencesDialog.b4xlib. lib.
2. Inside it you will see a Files folder that has all the internal layouts used by B4XPref for B4A, B4J and B4i.
3. Let us take a look at 'shortoptions.bal' layout. Open it in any B4A project. You will see a label and a B4XCombobox. In the tree hierarchy, B4XComboBox is the 2nd view. But since a B4XCombobox is an XUI Views customview, the object resides in its Tag. Hence, it is referred to as: GetView(1).Tag. See screenshot attached.
B4X:
If pi.ItemType = pref.TYPE_SHORTOPTIONS Then
            Dim c As B4XComboBox=pref.CustomListView1.GetPanel(i).GetView(1).Tag
The 'textitem.bal' layout has only a B4XFloatTextField. Hence: GetView(0).Tag
Same for these 3: pi.ItemType = prefdialog.TYPE_TEXT Or pi.ItemType = prefdialog.TYPE_NUMBER Or pi.ItemType = prefdialog.TYPE_PASSWORD
Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag

1694102629057.png
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Let us take a look at 'shortoptions.bal' layout. Open it in any B4A project. You will see a label and a B4XCombobox. In the tree hierarchy, B4XComboBox is the 2nd view. But since a B4XCombobox is an XUI Views customview, the object resides in its Tag. Hence, it is referred to as: GetView(1).Tag. See screenshot attached.
This gives me more clear idea.
Thanks a lot. šŸ™
 
Upvote 0
Top