Android Question CustomListView question

Discussion in 'Android Questions' started by Alberto Michelis, May 24, 2015.

  1. Alberto Michelis

    Alberto Michelis Active 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.
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    One idea, but not tested:
    extent the customlistviewclass with this method:
    Code:
    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:

    Code:
    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
     
    mangojack likes this.
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Nop, it does not work, it allways return -1
     
  4. RandomCoder

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice