Android Question Chage ListView Row/ITEM

Jose Paulo

Member
Licensed User
My Listview is LV1...

LV1.getitem(1)= "New York"
LV1.getitem(2)= "Paris"
LV1.getitem(3)= "Roma"

I need change item2 to "Kiev" on running...

How make it? Is replace? List view have only read-only properties?

Thanks
 

Jose Paulo

Member
Licensed User
Peter Simpson, thanks for attention,
With your solution i made two routines that solve and it´s down (I hope it is useful and there is nothing native alternative).
I still want to learn how to use XcustomListView as Erel said, i´m begginer in B4A.

B4X:
Sub ChangeItem (LST As ListView, Item As Int, NewValue As String)
    Dim CountItem As Int
    Dim LSTTemp As ListView
 
    LSTTemp.Initialize ("")
 
    For CountItem=0 To LST.Size-1
        If CountItem <> Item Then
            LSTTemp.AddSingleLine (LST.GetItem(CountItem))
        Else
            LSTTemp.AddSingleLine (NewValue)
        End If
    Next
 
    LST.Clear
 
    For CountItem=0 To LSTTemp.Size-1
        LST.AddSingleLine (LSTTemp.GetItem(CountItem))
    Next
End Sub

Sub UPItem (LST As ListView, Item As Int, DownItem As Boolean)
 
    Dim CountItem As Int
    Dim LSTTemp As ListView
 
    LSTTemp.Initialize ("")
 
    If DownItem=False And Item > 0 Or DownItem=True And Item < LST.Size Then
        For CountItem = 0 To LST.Size-1
            If CountItem <> Item Then
                If DownItem=False Or DownItem=True And CountItem <> Item+1 Then
                    LSTTemp.AddSingleLine (LST.GetItem(CountItem))
                End If
            Else
                If DownItem=False Then
                    LSTTemp.RemoveAt(CountItem-1)
                    LSTTemp.AddSingleLine (LST.GetItem(CountItem))
                    LSTTemp.AddSingleLine (LST.GetItem(CountItem-1))
                Else
                    LSTTemp.AddSingleLine (LST.GetItem(CountItem+1))
                    LSTTemp.AddSingleLine (LST.GetItem(CountItem))
                End If
            End If
        Next
     
        LST.Clear
 
        For CountItem=0 To LSTTemp.Size-1
            LST.AddSingleLine (LSTTemp.GetItem(CountItem))
        Next
    End If
End Sub

to use:
B4X:
ChangeItem(ListView3,2, "Tokyo") 'Item 2 of listview3 change to "Tokyo"
UPItem (ListView5, 4,True) 'Item 4 of listview5 up to previous line
UPItem (ListView7,8,False) 'Item 8 of listview7 down to next line

Thanks Peter Simpson. Thanks Erel.

Happy New Year!!! :)
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please use [CODE]code here...[/CODE] tags when posting code.

codetag001.png

codetag002.png

codetag003.png
 
Upvote 0
Top