Android Question TwoLinesAndBitmap getitem

glupinacci

Member
Licensed User
How can I retrieve values from TwoLinesAndBitmap (click event)?
When I use TwoLines, the last parameter is a Value, but using TwoLinesAndBitmap I dont know how get itens.

Example:
ListView1.AddTwoLines(Text, Text, Value)
ListView1.AddTwoLinesAndBitmap(Text, Text, Bitmap)

Is creating "Lists" or "Maps" the best approach?
Thanks in advance.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
You need to store what you put in the listview and then use the index like this...

B4X:
'In Process_Gloabls
'    Type LinesBitMap (line1 As String, line2 As String, bmp As Bitmap)
'            Click on LinesBitMap to generate CreatLinesBitMap automatically
'
'    Private ListItems As List

Sub Activity_Create(FirstTime As Boolean)
    ListItems.Initialize
    Dim aList As ListView
    aList.Initialize("aa")
    aList.TwoLinesAndBitmap.Label.SetTextColorAnimated(0, xui.Color_Blue)
    Activity.AddView(aList, 0, 0, 400dip, 400dip)

    ListItems.add(CreateLinesBitMap("a1", "b1", FontAwesomeToBitmap("AA", 20)))
    ListItems.add(CreateLinesBitMap("a2", "b2", FontAwesomeToBitmap("BB", 20)))
    ListItems.add(CreateLinesBitMap("a3", "b3", FontAwesomeToBitmap("CC", 20)))
    For Each lbm As LinesBitMap In ListItems
        aList.AddTwoLinesAndBitmap(lbm.line1, lbm.line2, lbm.bmp)
    Next
End Sub  

Public Sub CreateLinesBitMap (line1 As String, line2 As String, bmp As Bitmap) As LinesBitMap
    Dim t1 As LinesBitMap
    t1.Initialize
    t1.line1 = line1
    t1.line2 = line2
    t1.bmp = bmp
    Return t1
End Sub

Sub aa_ItemClick (index As Int, value As String)    'value is just the line1
    Dim lbm As LinesBitMap = ListItems.Get(index)
    Log(index & TAB & lbm.line1 & TAB & lbm.line2 & TAB & lbm.bmp.width)
End Sub
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
How can I retrieve values from TwoLinesAndBitmap (click event)?
When I use TwoLines, the last parameter is a Value, but using TwoLinesAndBitmap I dont know how get itens.

Example:
ListView1.AddTwoLines(Text, Text, Value)
...............................



Your example is a bit confusing ... AddTwoLines method does Not have a return Value.

AddTwoLines2 method does , likewise AddTwoLinesandBitmap2.

Capture.PNG


Just use these methods and your stored value will be returned in the Click Event or using .GetItem( )

If your want to store multiple return values populate a Map and pass that as the return value argument.


ps. If you have not already done so .. it might be in your interest to have a look at xCustomListView , which offers much more control with data display.
 
Last edited:
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@mangojack You're right of course. I haven't used the "2" version, so I missed that.
On the other hand, I never miss a chance to use "Type".

B4X:
Sub Activity_Create(FirstTime As Boolean)
    ListItems.Initialize
    Dim aList As ListView
    aList.Initialize("aa")
    aList.TwoLinesAndBitmap.Label.SetTextColorAnimated(0, xui.Color_Blue)
    Activity.AddView(aList, 0, 0, 400dip, 400dip)

    Dim aList As ListView
    aList.Initialize("aa")
    aList.TwoLinesAndBitmap.Label.SetTextColorAnimated(0, xui.Color_Blue)
    Activity.AddView(aList, 0, 0, 400dip, 400dip)

    Dim obj1 As Object = FontAwesomeToBitmap("AA", 20)
    Dim obj2 As Object = FontAwesomeToBitmap("BB", 20)
    Dim obj3 As Object = FontAwesomeToBitmap("CC", 20)
   
    aList.AddTwoLinesAndBitmap2("a1", "b1", obj1, obj1)
    aList.AddTwoLinesAndBitmap2("a2", "b2", obj2, obj2)
    aList.AddTwoLinesAndBitmap2("a3", "b3", obj3, obj3)
End Sub

Sub aa_ItemClick (index As Int, value As Object)
    Dim bmp As Bitmap = value
    Log(index & TAB & bmp.width)
End Sub
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
How can I retrieve values from TwoLinesAndBitmap (click event)?
When I use TwoLines, the last parameter is a Value, but using TwoLinesAndBitmap I dont know how get itens.

Example:
ListView1.AddTwoLines(Text, Text, Value)
ListView1.AddTwoLinesAndBitmap(Text, Text, Bitmap)

Is creating "Lists" or "Maps" the best approach?
Thanks in advance.

Here is an example source code of how to store the data in an array and use that array to retrieve the data later.
 

Attachments

  • test_listview.zip
    93.5 KB · Views: 207
Upvote 0
Top