B4J Question xCustomListView Problem: How to translate it to B4J

WebQuest

Active Member
Licensed User
Hi Community I'm translating my app from B4a to B4j.
I'm having problems replicating the loading functions in an xCustomListView in b4j. How can I translate this code into b4j?

B4a CODE:
'B4a CODE

Sub CreateListItemMessage(Nome1 As String, nrcell As String, email As String, testo As String,Date1 As String, Width As Int, Height As Int) As Panel
    
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0,0%y,Width,Height)
    p.LoadLayout("Layout_Set_Kunde")
    p.Color= Colors.White
    p.Elevation=3dip
'   
    Dim set As ColorDrawable
    set.Initialize2(Colors.Transparent,0,0,Colors.White)
    LName.Initialize("")
    LName.Width=100%x
    LName.TextColor=Colors.Green
    LName.TextSize=15
    LName.SingleLine=True
    LName.Text=Nome1
    'LName.Gravity= Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
    p.AddView(LName,7%x,2%y,30%x,4%x)
    
    Dim set As ColorDrawable
    set.Initialize2(Colors.Transparent,0,0,Colors.White)
    LPhone.Initialize("")
    LPhone.Width=100%x
    LPhone.Background=set
    LPhone.TextColor=Colors.Blue
    LPhone.TextSize=15
    LPhone.SingleLine=True
    LPhone.Text=nrcell
    'LPhone.Gravity= Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
    p.AddView(LPhone,7%x,5%y,21%x,4%x)
    
    Dim set As ColorDrawable
    set.Initialize2(Colors.Transparent,0,0,Colors.White)
    LMail.Initialize("")
    LMail.Width=100%x
    LMail.Background=set
    LMail.TextColor=Colors.LightGray
    LMail.TextSize=15
    LMail.SingleLine=True
    LMail.Text=email
    'LMail.Gravity= Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
    p.AddView(LMail,7%x,8%y,30%x,4%x)


    Dim set As ColorDrawable
    LMessage.Initialize("")
    LMessage.SingleLine=False
    LMessage.Width=100%x
    LMessage.TextColor=Colors.Gray
    LMessage.TextSize=15
    LMessage.SingleLine=False
    LMessage.Text=testo
    'LMessage.Gravity= Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
    p.AddView(LMessage,7%x,13%y,70%x,40%x)


    Dim set As ColorDrawable
    Ldate.Initialize("")
    Ldate.SingleLine=False
    Ldate.Width=100%x
    Ldate.TextColor=Colors.Gray
    Ldate.TextSize=15
    Ldate.SingleLine=False
    Ldate.Text=Date1
    'LMessage.Gravity= Bit.Or(Gravity.CENTER_HORIZONTAL,Gravity.CENTER_VERTICAL)
    p.AddView(Ldate,37%x,2%y,70%x,4%x)

    Return p
    
End Sub




Sub Load_ItemUser_Message
    
    Log("Load_Message")
    
    CustomListViewMessaggio.Clear
        
        For i = 0 To List_ID.Size-1
            CustomListViewMessaggio.Add(CreateListItemMessage(List_Nome.Get(i),List_Phone.Get(i),List_Mail.Get(i),List_Message.Get(i),List_Date.Get(i),85%x,40%y),List_ID)
        Next
    
End Sub
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4XView is a wrapper (XUI library) that hides "almost" all the view differences between platforms (b4A, B4J, B4i).
See https://www.b4x.com/guides/B4XXUI/?page=8
I assume that "Layout_Set_Kunde" has 5 editable views (LName, LPhone, LMail, LMessage, LDate)
These are all EditText in B4A. In B4J they are TextField.
After loading the layout, create their B4XView versions.
B4X:
Dim LNameX as B4XView = LName
Dim LPhoneX as B4XView = LPhone
'...

Then use the methods of B4XView to redesign your items.
Note that B4J views do not have an elevation parameter.
See https://www.b4x.com/android/forum/threads/b4x-xui-elevation-shadow.135767/post-858848

Also, note that you have an error in your code in #1. Views loaded from designer should not be initialized again.



[As an aside, B4XPages goes a long way toward hiding other differences between platforms]
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Dim p As Panel
B4X:
    Dim p As B4XView
    xui.CreatePanel("CLVItem")
    p.SetLayoutAnimated(0, 0, Width, Height)
    p.LoadLayout("layCLVItem")

Create the item layout (layCLVItem, here) USING THE DESIGNER, it is the best way to do it!


P.S. I only noticed now that you load a layout in Panel P, but then you still create the individual Views by code, I don't know why. All (or most, perhaps) that part is useless, as you create the layout of the item in the Designer.
 
Last edited:
Upvote 0
Top