Android Question UltimateListView

AndroidMadhu

Active Member
Licensed User
Hello All,
I am new in B4A and started working and exploring B4A.
I have been working with ULV with simple list view. But it is not working. Nothing showing in the list.
Below is my code...
B4X:
Sub Globals
    Dim ulv As UltimateListView
    Dim itemheight As Int = 60dip
    Dim fruits As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    fruits.Initialize2(Array As String("Apple", "Banana", "Cherry", "Coconut", "Grapes", "Lemon", "Mango", "Melon", "Orange", "Pear", "Pineapple", "Strawberry"))
    ulv.Initialize(0,0,"","ulv")
    ulv.Color=Colors.White
    Activity.AddView(ulv,0,0,100%x,100%y)
    ulv.AddLayout("MyTest","layout_creator","layout_contentfiller",itemheight,True)
    ulv.BulkAddItems(fruits.Size,"MyTest",0)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub layout_creator(LayoutName As String, LayoutPanel As Panel)
    LayoutPanel.LoadLayout("fruitlabel")
End Sub

Sub layout_contentfiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    Dim lbl As Label = LayoutPanel.GetView(0) 'First (and only) view in the panel
    lbl.Text = fruits.Get(Position)

Could anyone suggest why this is not showing the fruits name in the list?
 

DonManfred

Expert
Licensed User
Could anyone suggest why this is not showing the fruits name in the list?
I dont see you using the list!?
I mean except in the code
B4X:
 ulv.BulkAddItems(fruits.Size,"MyTest",0)
 
Upvote 0

skaliwag

Member
Licensed User
Your code looks fine.
I suspect either your text and paper colour are the same, so you can't see the text, or your layout is set up wrong
Try replacing your

LayoutPanel.LoadLayout("fruitlabel")

with

Dim lblName As Label
lblName.Initialize("")
lblName.TextColor=Colors.Black
LayoutPanel.AddView(lblName,0,0,LayoutPanel.Width,LayoutPanel.Height)

and see what happens.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
@skaliwag ... This is working fine .... Yes... the color are same.
Below is the code...
B4X:
#Region  Project Attributes
    #ApplicationLabel: ULV
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    Dim ulv As UltimateListView
    Dim itemheight As Int = 60dip
    Dim fruits As List
    Dim lblname As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    fruits.Initialize2(Array As String("Apple", "Banana", "Cherry", "Coconut", "Grapes", "Lemon", "Mango", "Melon", "Orange", "Pear", "Pineapple", "Strawberry", "Litchi", "Watermelon"))
    ulv.Initialize(0,0,"","ulv")
    ulv.Color=Colors.White
    ulv.AddLayout("MyTest","layout_creator","layout_contentfiller",itemheight,True)
    Activity.AddView(ulv,0,0,100%x,100%y)
    
    ulv.BulkAddItems(fruits.Size,"MyTest",0)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub layout_creator(LayoutName As String, LayoutPanel As Panel)
    lblname.Initialize("")
    lblname.TextColor=Colors.Gray
    LayoutPanel.AddView(lblname,20, 0 ,LayoutPanel.Width,LayoutPanel.Height)
    
End Sub

Sub layout_contentfiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    lblname.Text = fruits.Get(Position)
End Sub

One more confusion.... If I want to add a Panel at the back of ULV how Do I add then? As I want to add some button at the panel to fetch some data at ULV

Please advice
 
Upvote 0

Frankie Lagrange

Member
Licensed User
You should create a layout ('main' for example) to load into the activity using

B4X:
Activity.LoadLayout("main")

But if you really want to do everything by code, this will work: it creates a panel and a button in code.

B4X:
#Region  Project Attributes
    #ApplicationLabel: ULV
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    Dim ulv As UltimateListView
    Dim itemheight As Int = 60dip
    Dim fruits As List
    Dim lblname As Label
    Dim panel As Panel
    Dim btn As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("main")
    panel.Initialize("")
    panel.Height = 100%y
    panel.Width = 100%x
    panel.Color = Colors.Black

    btn.Initialize("")
    btn.Height = 50dip
    btn.Width = 100dip
    btn.Text = "BUTTON"
    btn.Color = Colors.Red
    
    panel.AddView(btn,  (100%x-btn.Width)/2, 100%y-btn.Height,100dip, 50dip)
    
    fruits.Initialize2(Array As String("Apple", "Banana", "Cherry", "Coconut", "Grapes", "Lemon", "Mango", "Melon", "Orange", "Pear", "Pineapple", "Strawberry", "Litchi", "Watermelon"))
    ulv.Initialize(0,0,"","ulv")
    ulv.Color=Colors.White
    ulv.AddLayout("MyTest","layout_creator","layout_contentfiller",itemheight,True)
    Activity.AddView(panel,0,0,100%x, 100%y)
    ulv.BulkAddItems(fruits.Size,"MyTest",0)
    
    panel.AddView(ulv,0,0,100%x, 80%y)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub layout_creator(LayoutName As String, LayoutPanel As Panel)
    lblname.Initialize("")
    lblname.TextColor=Colors.Gray
    LayoutPanel.AddView(lblname,20, 0 ,LayoutPanel.Width,LayoutPanel.Height)
    
End Sub

Sub layout_contentfiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    lblname.Text = fruits.Get(Position)
End Sub
 
Last edited:
Upvote 0

AndroidMadhu

Active Member
Licensed User
Activity.LoadLayout("main")
Yes... I have done that... I want to add the name in another way.
Below is my code

B4X:
#Region  Project Attributes
    #ApplicationLabel: ULV1
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private UltimateListView1 As UltimateListView  <---From Desiner Control[Generate target]
    Private btn1 As Button <---From Desiner Control[Generate target]
    Private fruits As List <---From Desiner Control[Generate target]
    Private Label1 As Label <---From Desiner Control[Generate target]
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    fruits.Initialize2(Array As String("Apple","Melon","Litchi", "Strawberry","Blueberry"))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub UltimateListView1_LayoutCreator(LayoutName As String, LayoutPanel As Panel)

End Sub

Sub UltimateListView1_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    Label1.TextColor=Colors.Red
    Label1.Text= fruits.Get(Position)
End Sub

Am I missing anything? Please suggest....
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Yes.. I have created panel in main layout (Designer layout). At designer view first I create the panel. Then I created ulv on top of this panel. I also add label on ulv and add button inside the panel
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
I wanted to see the name of the fruits at the list view. But they are not showing. Am I doing any mistake ? Like I have not written anything at
B4X:
UltimateListView1_LayoutCreator
Also I made the panel "Send to back" at Designer View. Not sure where I am wrong?
 
Upvote 0

Frankie Lagrange

Member
Licensed User
Here's a project that works. Hopefully it'll help you. I mean, it's your project working.

And my opinion, for what it's worth: xCLV is easier to implement and runs on many platforms. ULV is dedicated to Android (I believe), but has more features. In particular it has a very smooth drag and drop function that xCLV lacks.
 

Attachments

  • x.zip
    9.8 KB · Views: 131
Last edited:
Upvote 0

Mahares

Expert
Licensed User
If anyone advice where I am wrong it will be helpful
Here is attached a complete fruit project in xCustomListView in its simplest form that does exactly what you are trying to do with Frankie's help using ULV.
B4X:
Sub Globals
    Private clv1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")  'has  clv1 only
    Dim MyList As List
    MyList.Initialize
    MyList = Array ("Apple", "Banana", "Cherry", "Coconut", "Grapes", "Lemon", "Mango", "Melon", "Orange", "Pear", "Pineapple", "Strawberry", "Litchi", "Watermelon")
    For Each s As String In MyList
        clv1.AddTextItem(s, s)
    Next
End Sub

Sub clv1_ItemClick (Index As Int, Value As Object)
    Activity.Title = $"My favorite fruit is: ${Value}"$
     MsgboxAsync( $"I clicked on: ${Value}"$,"Favorite Fruit")
End Sub
 

Attachments

  • xCLVinItsSimplestForm941720.zip
    8.2 KB · Views: 116
Last edited:
Upvote 0
Top