Android Question identifying a customlistview and modify (b4xpages)

Lucas Siqueira

Active Member
Licensed User
Longtime User
I have 5 components without my designer.
I want to modify them through a function, the problem and when identifying a customlistview, for some reason I can't know what type of component it is.


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As B4XView
    Private EditText1 As B4XView
    Private Label1 As B4XView
    Private CustomListView1 As CustomListView
    Private B4XFloatTextField1 As B4XFloatTextField
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Private Sub B4XPage_Appear
    formatar_campos
End Sub

Private Sub Button1_Click
    CustomListView1.AddTextItem(EditText1.Text & CRLF & B4XFloatTextField1.Text,Null)
End Sub

Private Sub formatar_campos
  
    'For Each v As B4XView In Root.GetAllViewsRecursive
    For i=0 To Root.NumberOfViews-1
        Dim v As B4XView = Root.GetView(i)
      
        If v Is CustomListView Then
            Log("CustomListView")
            Dim v3 As CustomListView = v
            v3.AsView.Color=xui.Color_Blue
          
        else If v.Tag Is CustomListView Then
            Log("CustomListView")
            Dim v3 As CustomListView = v
            v3.AsView.Color=xui.Color_Red
          
        Else If v.Tag Is B4XFloatTextField Then
            Log("B4XFloatTextField")
            Dim v2 As B4XFloatTextField = v.Tag
            v2.TextField.SetColorAndBorder(xui.Color_Black,0,0,10dip)
            v2.TextField.TextColor=xui.Color_White
            v2.TextField.TextSize=18
            v2.TextField.SetTextAlignment("CENTER","CENTER")
            v2.Update
          
        Else If v Is EditText Then
            Log("EditText")
            v.SetColorAndBorder(xui.Color_LightGray,0,0,10dip)
            v.TextColor=xui.Color_DarkGray
            v.TextSize=18
            v.SetTextAlignment("CENTER","CENTER")
          
        Else If v Is Button Then
            Log("Button")
            v.SetColorAndBorder(xui.Color_Green,0,0,10dip)
            v.TextColor=xui.Color_White
            v.TextSize=22
            v.SetTextAlignment("CENTER","CENTER")
          
        Else If v Is Label Then
            Log("Label")
            v.Color=xui.Color_Transparent
            v.TextColor=xui.Color_Red
            v.TextSize=18
            v.SetTextAlignment("CENTER","CENTER")
          
        End If
      
    Next
  
End Sub


1635863119511.png
 

Attachments

  • Project.zip
    14.9 KB · Views: 114

Lucas Siqueira

Active Member
Licensed User
Longtime User
Solution

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As B4XView
    Private EditText1 As B4XView
    Private Label1 As B4XView
    Private CustomListView1 As CustomListView
    Private B4XFloatTextField1 As B4XFloatTextField
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    CustomListView1.AsView.Tag = CustomListView1
End Sub

Private Sub B4XPage_Appear
    formatar_campos
End Sub

Private Sub Button1_Click
    CustomListView1.AddTextItem(EditText1.Text & CRLF & B4XFloatTextField1.Text,Null)
End Sub

Private Sub formatar_campos
 
    For Each v As B4XView In Root.GetAllViewsRecursive
     
        If v.Tag Is CustomListView Then
            Log("CustomListView")
            Dim v3 As CustomListView = v.Tag
            v3.AsView.Color=xui.Color_Red
        End If
     
    Next
 
End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sub Class_Globals

The code you have in Private Sub formatar_campos does not sound correct and does not work. You get an error on this line:
B4X:
Dim v3 As CustomListView = v
java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to b4a.example3.customlistview
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
The code you have in Private Sub formatar_campos does not sound correct and does not work. You get an error on this line:
B4X:
Dim v3 As CustomListView = v
java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to b4a.example3.customlistview
Dim v3 As CustomListView = v.Tag
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Dim v3 As CustomListView = v.Tag
Your corrected project works well if you have only one view of each type. But if you have more than one view of a given type, then, it will not work. For instance, If you have 2 customlistviews , you have to identify each xClv with its position index in the designer views tree to differentiate between them. Otherwise, you are just doubling up.
 
Upvote 0
Top