Need help with Lists

Jamie

Member
Licensed User
Longtime User
I'm having trouble figuring this out.
I create a list called Book. Then I load in a csv file that has 5 items per line.
B4X:
Book.Initialize
Book = su.LoadCSV(File.DirRootExternal, "Book.csv", ",")
I can then match a Value from a listview and get the info from the Book list by putting it into an array
B4X:
Sub ListView2_ItemLongClick (Position As Int, Value As Object)
   For i = 0 To Book.Size -1
     Dim cells() As String   
   cells = Book.Get(i)
    If Value = cells(0) Then
   Dim result As Int
   result = Msgbox2("Save ?"& CRLF & cells(0) &"="& cells(1)"="&cells(2)&"="&cells(3), "", "Yes", "", "No", Null)
      If result = DialogResponse.POSITIVE Then
      newlist.addall(cells) 'this is where my problem seems to be
      Log("Newlist size=" & newlist.Size) '1 if using .add and 5 if using .addall
      ListView3.Visible=True
      ListView3.AddSingleLine(newlist.Get(0)) 'using 0 position for testing only
      
      End If  
   End If
Next
End Sub
If I use newlist.addall(cells) the info is added on separate lines in the list.
If I use newlist.add(cells) and then try to place it in a listview
I get this [Ljava.lang.String;@4135d700 in the listview.
I need to create a list just like the book list with multiple items per line that I can access in the same fashion to manipulate and then I can save it back to a different .csv file
Thanks
Jamie.
 

mc73

Well-Known Member
Licensed User
Longtime User
I'm no expert on list manipulation, but perhaps you could try something like this?
B4X:
dim listItem as string
listItem=""
for k=0 to cells.length-1
listItem=listItem & "," & cells(k)
next
newList.add(listItem.substring(1))
Perhaps this helps, I don't know...
 
Upvote 0

Jamie

Member
Licensed User
Longtime User
Thanks for the response mc73. I had tried something like that and it does put the info all on 1 line but unlike the book list it is 1 item and not separate items as is the case with book list. Maybe what I want to do is only possible when reading in a csv file using stringutilities or maybe I'm just missing something. :sign0161:
Worst case I can concatenate the strings as needed for a csv then save it then reread it using stringutilities into the same type of list as book, manipulate the data as needed then concatenate again and save, or tear down the string and rebuild then save. Big pain, same outcome.
Hopefully someone will know if I can fill the list exactly like the book list.
Thanks
 
Upvote 0

Jamie

Member
Licensed User
Longtime User
I found a solution that works, should have thought about it before, had different problem a few days ago and used the same solution.:sign0161: seems that Smiley really says it all

anyway the solution was to create a TYPE.
fill the type with the cell values
then ListView3.AddTwoLines2(prd.Code &"'"& prd.Cat &"'"& prd.Desc, prd.Sell &"'"& prd.Cost,prd).
on the Listview3_ItemClick event fill type with value.
Then it's simple to pull a specific item, eg. prd.sell and change it and put it back in listview for later saving or changing.

Still like to know why newlist.add(cells) won't work

Turns out I can simply send cells as the value and it works fine also
ListView3.AddTwoLines2(prd.Code &"'"& prd.Cat &"'"& prd.Desc, prd.Sell &"'"& prd.Cost,cells)
 
Last edited:
Upvote 0

Jamie

Member
Licensed User
Longtime User
Final :sign0161:
newlist.add(cells) worked just fine. The problem was the way I tried to put it in the listview. What I had to do was put the individual items in the listview. then to view all items in the newlist I can just loop through like so.

B4X:
For i = 0 To newlist.Size-1
   Dim cells() As String
   cells=newlist.Get(i)
   Log(cells(0)&cells(1)&cells(2))
   Next
 
Upvote 0
Top