ListView Second Line

rfhall50

Member
Licensed User
Longtime User
My listview is named ListView1 (as you can see). It is a 2 line view, no graphic. When I execute the following code, I get the first line just as you would expect.

MagBox(ListView1.GetItem(position). "")

Can someone put it into plain English (sorry to be a language snob) how I can get the SECOND line. I have read all the tutorals and the questions and answers, but I just don't understand.

Compared to how easy it is to get the FIRST line, it seems overly complicated to get the SECOND line. But, I am probably wrong.

Thank You.
Bob
 

rfhall50

Member
Licensed User
Longtime User
Yes, the list view works fine. It is populated and displays fine. I can scroll through the list OK. I can tap an entry and display a panel with line 1 info. I just can't figure out how to extract line 2 data.
BTW, I have read that. I just can't figure out the line 2 part.

Thank you.
Bob
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Either use the option above or if your not confident using a custom type then you could create 2 arrays to load the data from. 1 for first line data other for second line data. List from these arrays. Use AddTwoLines2 and store the array index in the Return Value.
i.e

B4X:
Sub Process_Globals
Dim ListLine1() as string
Dim ListLine2() as string
...

Sub Activity_Create(FirstTime as Boolean)
ListLine1 = Array as string("item1", "item2", "item3",....)
ListLine2 = Array as string("item1_Description", "item2_Description", "item3_Description", .....)

For i = 0 to (ListLine1.Length - 1)
    ListView.AddTwoLines2(ListLine1(i), ListLine2(i), i)
Next
....

Sub ListView_ItemClick (Position As Int, Value As Object)
    Msgbox(ListLine2(value), ListLine1(value))
end sub

Hope you can understand that and that it will be useful to you.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Yes, the list view works fine. It is populated and displays fine. I can scroll through the list OK. I can tap an entry and display a panel with line 1 info. I just can't figure out how to extract line 2 data.
BTW, I have read that. I just can't figure out the line 2 part.

Thank you.
Bob

Bob :

Have you defined your ListView like this?

Sub Globals
Type ListViewData (FirstRow As String, SecondRow As String)
End Sub



It would help if you could post some code, to see what you are doing and how you are intending to use the data...
 
Upvote 0

rfhall50

Member
Licensed User
Longtime User
Thank all of you for the responses. I don't care for duplicating the data in a second table, but am definitely keeping that option alive !

In looking again at Erel's example, I finally noticed something that may be the key. In the AddTwoLines2 format of ListView, what is the purpose or definition of the third argument (lvd). The examples I've looked at only had a third argument when it was AddTwoLinesandBitmap.

B4X:
Sub Globals
 Type ListViewData (FirstRow As String, SecondRow As String)
End Sub

For i = 0 to 100
 Dim lvd As ListViewData
 lvd.Initialize
 lvd.FirstRow = "abc"
 lvd.SecondRow=  "def"
 ListView1.AddTwoLines2(lvd.FirstRow, lvd.SecondRow, [COLOR="Red"]lvd[/COLOR])
Next


Sub ListView1_ItemClick(Position As Int, Value As Object)
 Dim lvd As ListViewData
 lvd = Value
 ...
End Sub
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
The third argument is the 'return value' that is returned when you click an item. In the example it stores a custom type (declared at the top) called listviewdata. This contains the FirstRow and SecondRow elements.
 
Upvote 0

rfhall50

Member
Licensed User
Longtime User
ListView Second Line - Thank You !!!

:sign0098: Thanks to all of you for your help and patience. I have finally seen the light on the second line of data. I don't understand all the constructs in the code, but I know I can do it again when needed.

Again, Thanks to all of You !

Bob
 
Upvote 0
Top