Android Question UltimateListView Dynamic List Creation

AndroidMadhu

Active Member
Licensed User
Hello,
While creating dymanic items in ultimateListview I am getting error as below :

B4X:
Error occurred on line: 61 (Main)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=10; index=12
    at java.util.Arrays$ArrayList.get(Arrays.java:3769)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
    at b4a.example.main._ulv_contectfill(main.java:438)

The below is my code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #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.
Dim mylist As List
    Private Pnl As Panel
    Private ULV As UltimateListView
    Dim mylist As List
    Dim itemheight As Int=60dip
    Dim Somearray(10) As String
    Dim lbl As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    mylist.Initialize2(Somearray)
    'Add the ULV Add view
    ULV.AddLayout("MyList","ULV_Layoutcallback","ULV_ContectFill",itemheight,True)
    'For loop to dynamically create the item
    For i=0 To mylist.Size
        ULV.BulkAddItems(mylist.Size,"MyList",0)
    Next
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub ULV_Layoutcallback(LayoutName As String, LayoutPanel As Panel)
    lbl.Initialize("")
    lbl.TextColor=Colors.Black
    LayoutPanel.AddView(lbl,20,0, LayoutPanel.Width,LayoutPanel.Height)
End Sub

Sub ULV_ContectFill(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)
    lbl.Text=mylist.Get(Position)
End Sub

Please advice
 

OliverA

Expert
Licensed User
Longtime User
For i=0 To mylist.Size ULV.BulkAddItems(mylist.Size,"MyList",0) Next
Up front: I have no clue how to use ULV
This though looks like you are adding mylist.Size * mylist.Size items to the list (in your case 100). I think the code should just be
B4X:
ULV.BulkAddItems(mylist.Size,"MyList",0)
without the for/next[/code]
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

AndroidMadhu

Active Member
Licensed User
Yes.... I got it... but if I want to push the value I need to run for loop to put the value within the array.
I am not able to push the value within the array.
How do I achieve this??? Plz advice
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
but if I want to push the value I need to run for loop to put the value within the array.
I am not able to push the value within the array.
This for loop
B4X:
    For i=0 To mylist.Size
        ULV.BulkAddItems(mylist.Size,"MyList",0)
    Next
had nothing to do with putting values into the array Somearray. Either do a
B4X:
Somearray = Array As String ("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten")
before
B4X:
mylist.Initialize2(Somearray)
Are don't use the array and do something like
B4X:
mylist.initialize
'Now write some code to add your items to the mylist list
'Maybe code that reads from a database, or pulls stuff from the web, or reads a local text file for values
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…