Android Question AddTwoLinesAndBitmap2 & ReturnValue

luke2012

Well-Known Member
Licensed User
Longtime User
Hi to All,
About AddTwoLinesAndBitmap2 documentation says: "The specified return value will be returned when calling GetItem or in the ItemClick event"

Using GetItem I'm able to obtain the ReturnValue but how to obtain the ReturnValue within the ItemClick event ?

Thanks in advance!
 

DonManfred

Expert
Licensed User
Longtime User
What is the code you are using?
The ItemClick Event will give you a parameter value. This is the value you set with AddTwoLinesAndBitmap2 in the last parameter,
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
My target is to associate an Item ID to each listview item.

So the sintax is:

B4X:
AddTwoLinesAndBitmap2 (Text1 As String, Text2 As String, Bitmap As android.graphics.Bitmap, ReturnValue As Object)

For example:

B4X:
private ItemID as object

ItemID = 1
AddTwoLinesAndBitmap2 ("This is item n.1", "", aImg, ItemID)

ItemID = 2
AddTwoLinesAndBitmap2 ("This is item n.2", "", aImg, ItemID)

ItemID = 3
AddTwoLinesAndBitmap2 ("This is item n.3", "", aImg, ItemID)

After I wish to be able to obtain the item ID using .GetItem or within an _ItemClick event.
In this case I wish to have the displayed text (for user) and the hidden ID for items lookup.

See the attached sample...
 

Attachments

  • listview_sample.zip
    38.8 KB · Views: 319
Last edited:
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
In your example you set the ID return value as a random number ??

Why not just the order added to the listview .
B4X:
For i = 1 To 10
     lsv.AddTwoLinesAndBitmap2 ("Item #" & i, "", LoadBitmap(File.DirAssets, "pri_default.png"), $"ID ${i}"$)
  Next
or am I missing something ...
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
In your example you set the ID return value as a random number ??

Why not just the order added to the listview .
B4X:
For i = 1 To 10
     lsv.AddTwoLinesAndBitmap2 ("Item #" & i, "", LoadBitmap(File.DirAssets, "pri_default.png"), $"ID ${i}"$)
  Next
or am I missing something ...

ID as a Random number is an example but in the real app I have a SQLite incremental ID that don't match with the listview order.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
ID as a Random number is an example but in the real app I have a SQLite incremental ID that don't match with the listview order.

Rnd number is to simulate the SQLite incremental ID that I have to store within the listview item.
So I have a mapping between Item Text ("This is item n...") and the Record ID (SQLite incremental ID).

The ID I wish to put is the SQLite record ID related to the item.
So the item value is the text displayed within the listview to the user and the Record ID is stored within the ReturnValue object.

Is it possible ?

P.S.
Could be that I don't understand well the documentation :)
Probably @Erel could give a clear explanation about it.
 
Last edited:
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
The 'ReturnValue' is passed as the second parameter to ItemClick.

OK. Instead of the item text the second parameter contains the Return Value. No way to read the corresponding item text within the ItemClick event?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
If you want to get teh ItemID and the text as the return value you could define a Type variable which holds both values.
When you click onto an item you'll get the Type value back. You can then get the text and the ItemID.

In my database projects I use a separte List with the rowIDs.
I fill a Spinner with the texts and a list with the rowIDs.
For a given position I know the text and the rowID.
 
Upvote 0
Top