Android Question How to change item text on xCustomListView?

cenyu

Active Member
Licensed User
Longtime User
Hello,
I have one xCustomListView anl a small list of items witch i use to display some customer info:
B4X:
    CLV1.Add(CreateListItem("Access type", CLV1.AsView.Width, 60dip), $"Item #${1}"$)
    CLV1.Add(CreateListItem("Access date", CLV1.AsView.Width, 60dip), $"Item #${2}"$)

When user click on CLV1 item and change this setting my CLV1 item have to change it's text according to user selection. Is it possible to change item text dinamicly by Item index?

I only find how to add item:
B4X:
Private Sub CLV1_ItemClick (Index As Int, Value As Object)
    ToastMessageShow(Index,True)
    CLV1.InsertAtTextItem(Index,"JABA",Value)
End Sub
 
Solution
It looks that your items are all AddTextItem, right?
In the case try this
B4X:
CLV1.GetPanel(index).GetView(0).Text = "NEW TEXT HERE"

cenyu

Active Member
Licensed User
Longtime User
I found a solution. It's simle but works!
B4X:
CLV1.InsertAtTextItem(Index,"JABA",Value)
CLV1.RemoveAt(Index)
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
It looks that your items are all AddTextItem, right?
In the case try this
B4X:
CLV1.GetPanel(index).GetView(0).Text = "NEW TEXT HERE"
 
Upvote 1
Solution

Mahares

Expert
Licensed User
Longtime User
I found a solution. It's simle but works!
The code you have in post #2 does not look correct. The lines should be reversed. It should be:
B4X:
clv1.RemoveAt(Index)    
clv1.InsertAtTextItem(Index,"JABA",Value)
The solution that @Sagenut gave you in post #3 works too.
 
Upvote 1

Sagenut

Expert
Licensed User
Longtime User
.GetPanel(0)?
I have no panel...
Every CLV item is basically a Panel and it's needed to reference the one (using the Index) that you want to access to work on it.
 
Upvote 0

cenyu

Active Member
Licensed User
Longtime User
But when try this code i receive "Object have to be initialized first" error.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
We should see your code to better understand.
Today I am unable to send you an example.
I can do it tomorrow, if someone does not help you earlier.
 
Upvote 0

cenyu

Active Member
Licensed User
Longtime User
Here is my code:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private CLV1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    CLV1.Add(CreateListItem("Access type", CLV1.AsView.Width, 60dip), "AccessType")
    CLV1.Add(CreateListItem("Access date", CLV1.AsView.Width, 60dip), "StartDate")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
    Return p
End Sub


Private Sub CLV1_ItemClick (Index As Int, Value As Object)
    ToastMessageShow(Index,True)
'    CLV1.RemoveAt(Index)
'    CLV1.InsertAtTextItem(Index,"JABA",Value)
   
    CLV1.GetPanel(0).GetView(Index).Text = "NEW TEXT HERE"
   
End Sub

Into layout CellItem i have one label and button...

And thanks for your time! I appreciate your help, Sagenut!

 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
nd thanks for your time! I appreciate your help
You need to get the index of the panel not the index of the label, and then inside that panel is the firt label at position 0 referred to as GetView(0)
This line:
B4X:
CLV1.GetPanel(0).GetView(Index).Text = "NEW TEXT HERE"
Should be like below:
B4X:
CLV1.GetPanel(index).GetView(0).Text = "NEW TEXT HERE"
 
Upvote 0

cenyu

Active Member
Licensed User
Longtime User
You need to get the index of the panel not the index of the label, and then inside that panel is the firt label at position 0 referred to as GetView(0)
This line:
B4X:
CLV1.GetPanel(0).GetView(Index).Text = "NEW TEXT HERE"
Should be like below:
B4X:
CLV1.GetPanel(index).GetView(0).Text = "NEW TEXT HERE"

Perfect! Thank you! It's work now... Sagenut was rigth :) Stupid me! :))
 
Upvote 0
Top