ListView Tag

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I have list view - reading from database
and I added tag value for each line

how do I read the line tag after I click certain line?
 

dealsmonkey

Active Member
Licensed User
Longtime User
Hi

I have list view - reading from database
and I added tag value for each line

how do I read the line tag after I click certain line?

use the listview.AddSingleLine2(databasecolumn1,databasecolumn2)

then :

B4X:
sub listview_ItemClick (Position As Int, Value As Object)

dim myitem as string

myitem = value        <--- This will contain the databasecolumn2 value..

end sub
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
Cursor = SQL1.ExecQuery("SELECT * FROM CustomerList")
If Cursor.RowCount > 0 Then
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
ListView_CustomerList.SingleLineLayout.Label.Gravity = Gravity.RIGHT
ListView_CustomerList.AddSingleLine (Cursor.GetString("Price") & " ")
ListView_CustomerList.Tag = (Cursor.GetString("Makat"))
Next
End If
Cursor.Close


I need the tag information not to be show in the table
but I need it's value to pass for other tables queries
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
I can do it but

on my list view, (table - unless list view is not good to use here)
I need each line to have 2 column, one will have hidden value (will not show)
and i need to use the hidden value when clicked
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
Cursor = SQL1.ExecQuery("SELECT * FROM CustomerList")
If Cursor.RowCount > 0 Then
For i = 0 To Cursor.RowCount - 1
Cursor.Position = i
ListView_CustomerList.SingleLineLayout.Label.Gravity = Gravity.RIGHT
ListView_CustomerList.AddSingleLine (Cursor.GetString("Price") & " ")
ListView_CustomerList.Tag = (Cursor.GetString("Makat"))
Next
End If
Cursor.Close


I need the tag information not to be show in the table
but I need it's value to pass for other tables queries


if you use :

ListView_CustomerList.AddSingleLine2(Cursor.GetString("Price") & " ",Cursor.GetString("Makat"))

then

The Price will be shown, but the Makat will not be shown but will be available in the click event, where it is the value object. Does this sound like you want ?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Your code will not work:
- ListView_CustomerList.SingleLineLayout.Label.Gravi ty = Gravity.RIGHT
It os not necessary to put this line in the For/Next loop, putting it outsides of the loop is enough, because it defines the gravity for all entries.
- ListView_CustomerList.Tag, is the Tag of the ListView and not for each entry!
I would suggest you following code:
B4X:
Cursor = SQL1.ExecQuery("SELECT * FROM CustomerList")
If Cursor.RowCount > 0 Then
  ListView_CustomerList.SingleLineLayout.Label.Gravity = Gravity.RIGHT
  For i = 0 To Cursor.RowCount - 1
    Cursor.Position = i
    ListView_CustomerList.AddSingleLine2(Cursor.GetString("Price") & " ",Cursor.GetString("Makat"))
  Next
End If
Cursor.Close
In this case the value in a ListView_ItemClick event will be Cursor.GetString("Makat")

Best regards.

EDIT: I just saw that dealsmonkey was faster than I
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
Your code will not work:
- ListView_CustomerList.SingleLineLayout.Label.Gravi ty = Gravity.RIGHT
It os not necessary to put this line in the For/Next loop, putting it outsides of the loop is enough, because it defines the gravity for all entries.
- ListView_CustomerList.Tag, is the Tag of the ListView and not for each entry!
I would suggest you following code:
B4X:
Cursor = SQL1.ExecQuery("SELECT * FROM CustomerList")
If Cursor.RowCount > 0 Then
  ListView_CustomerList.SingleLineLayout.Label.Gravity = Gravity.RIGHT
  For i = 0 To Cursor.RowCount - 1
    Cursor.Position = i
    ListView_CustomerList.AddSingleLine2(Cursor.GetString("Price") & " ",Cursor.GetString("Makat"))
  Next
End If
Cursor.Close
In this case the value in a ListView_ItemClick event will be Cursor.GetString("Makat")

Best regards.

Sorry, but I just want to ask, now that you got the value returned corectly, how about to return let's say two values? One for the *client_id* integer for example and the other one *Makat*. Is this possible?
 
Upvote 0

AscySoft

Active Member
Licensed User
Longtime User
Yes indeed, I was able to create a custom type and solved the problem. But just a related question now: If I create a custom type with 3 elements(1,2 - strings, 3-integer) and in the listview I will load approx 500 records...is this gonna be costly in system resources? Would be much easier with a native peoperty solution, say ListView1.GetItem(position).FirstLine, ListView1.GetItem(position).SecondLine - , and value (as it is now)... get the idea
 
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
I have been trying to get similar to Shay, however using
lv.AddSingleLine(" " & main.cursor1.GetString("location")& " " & main.cursor1.GetString("description")& " " & main.cursor1.GetString("buy") & " "& ,main.cursor1.GetString("ID"))

just throws me an error at the comma entry, is it an issue with it referencing back to the main activity?

Without the comma it shows, but shows the ID field as well.

I have been trying
lv.SingleLineLayout.Label.Tag = main.cursor1.GetString("ID")
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It looks like you want AddsingleLine2 see here

But you also have an extra '&' before the comma.

It would work as either:

lv.AddSingleLine(" " & main.cursor1.GetString("location")& " " & main.cursor1.GetString("description")& " " & main.cursor1.GetString("buy") & " "& main.cursor1.GetString("ID"))

or

lv.AddSingleLine2(" " & main.cursor1.GetString("location")& " " & main.cursor1.GetString("description")& " " & main.cursor1.GetString("buy"), main.cursor1.GetString("ID"))

The second will display everything before the comma, and return the value after the comma when selected.
 
Last edited:
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
Oh thank you!
The comma replaces the & instead of being with it. That makes sense. Are there other characters that have special properties like that?
 
Upvote 0
Top