Android Question [B4X] Update the value of a CLV Item

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone,
I have the necessity to update the value associated with an item of a CustomListView, the only method available is .GetValue but it does not accept the association operator (=).

I do not want to recreate the view every time because the values will change rapidly and i do not want to have any "glitchy" effect on it.
Is there any way to do it?

Thanks in advance
 
Solution
Use the xclv.GetRawListItem(2).Value method to update the value.
B4X:
    For i = 0 To 20 -1
        
        Dim xpnl As B4XView = xui.CreatePanel("")
        xpnl.SetLayoutAnimated(0,0,0,Root.Width,20dip)
        xpnl.Color = xui.Color_ARGB(255,Rnd(0,256),Rnd(0,256),Rnd(0,256))
        xclv.Add(xpnl,"InsertedValue: " & i)
        
    Next
    
    Sleep(3000)
    Log(xclv.GetValue(2))
    xclv.GetRawListItem(2).Value = "UpdatedValue: " & 2
    Log(xclv.GetValue(2))

attached is an B4J project, the code works on b4a too .

Mike1970

Well-Known Member
Licensed User
Longtime User
That depends on what you want to update, you don't give any information about your implementation.
Hi Alexander,
What do you mean? I said everything needed to understand what I wish to accomplish, it is a generic thing.

I have a CustomListView with various items in it (it is not relevant what items), and every CLV Item has a Value (by library, it is not an implementation of mine).
(I mean the same Value that you receive in the _ItemClick callback of CLVs).

What I need is to be able to update this value for a specific Item in the CLV.
For example what is intuitive to have is a method like .setValue(Index, NewValue) like it is done for the normal Lists, but this method does not exists, so seems impossible to update the value for an already existing item in the CLV in a clean way.
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Use the xclv.GetRawListItem(2).Value method to update the value.
B4X:
    For i = 0 To 20 -1
        
        Dim xpnl As B4XView = xui.CreatePanel("")
        xpnl.SetLayoutAnimated(0,0,0,Root.Width,20dip)
        xpnl.Color = xui.Color_ARGB(255,Rnd(0,256),Rnd(0,256),Rnd(0,256))
        xclv.Add(xpnl,"InsertedValue: " & i)
        
    Next
    
    Sleep(3000)
    Log(xclv.GetValue(2))
    xclv.GetRawListItem(2).Value = "UpdatedValue: " & 2
    Log(xclv.GetValue(2))

attached is an B4J project, the code works on b4a too .
 

Attachments

  • Eample B4J.zip
    3.5 KB · Views: 13
Upvote 1
Solution

Mike1970

Well-Known Member
Licensed User
Longtime User
Use the xclv.GetRawListItem(2).Value method to update the value.
B4X:
    For i = 0 To 20 -1
       
        Dim xpnl As B4XView = xui.CreatePanel("")
        xpnl.SetLayoutAnimated(0,0,0,Root.Width,20dip)
        xpnl.Color = xui.Color_ARGB(255,Rnd(0,256),Rnd(0,256),Rnd(0,256))
        xclv.Add(xpnl,"InsertedValue: " & i)
       
    Next
   
    Sleep(3000)
    Log(xclv.GetValue(2))
    xclv.GetRawListItem(2).Value = "UpdatedValue: " & 2
    Log(xclv.GetValue(2))

attached is an B4J project, the code works on b4a too .
oh awesome, so accessing the Value from the method GetRawListItem enables also the association operation D: ?
Well this is counter-intuitive, but thanks to pointing me to the solution that I wouldn't figure out myself.
 
Upvote 0
Top