Android Question CustomListView question

Alberto Michelis

Well-Known Member
Licensed User
Hi, I need to show stocks prices.
This prices change while the user is seeing the List and the user must see that change.
I have a timer when I read the prices.
The stocks (items) are not identified by a number (index), they are identified by a string, like "AAPL".
How can I look for "APPL" in a view of the panel so I can add or remove and add it again?
Other way is get the row number at the Add() and save "AAPL" and RecNr in a queue or somethig similar I dont know in B4A.

The code would be like:

If "AAPL" does not exists in the CUstomLIstView Then
Prices.Add(CreateListItem(tiket, Prices.AsView.Width, 50dip), 50dip, RecNr)
Else
'Add ti at the same row it was
RecNr = ????
Prices.RemoveAt(RecNr )
Prices.InsertAt(RecNr , CreateListItem(tiket, Prices.AsView.Width, 50dip) , 50dip, RecNr )
End If

Thanks in advace.
 

eurojam

Well-Known Member
Licensed User
One idea, but not tested:
extent the customlistviewclass with this method:
B4X:
Public Sub FindItem (o As Object) As Int
  Dim index As Int
  index = items.IndexOf(o)
  Return index
End Sub
and then in your codemodul, you can search the items of the customlistview like:

B4X:
Sub find
  Dim index As Int

  index = prices.FindItem("AAPL")
  If index = -1 Then
    'add new item
  Else
    'do anything else
  End If

End Sub
 

RandomCoder

Well-Known Member
Licensed User
Use a Map to store the unique String as the Key i.e. "AAPL" and the value can be the index to which it is stored in the CustomListView.
 
Top