Android Question How to set values of items inside CLV ?

Adamdam

Active Member
Licensed User
Longtime User
Dear all.
Greetings,
I need to set values for certain item in CLV, how?
the following part of code but not work right.
B4X:
Sub Globals
    Private CLV1                As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    Activity.LoadLayout  ("1")
End Sub

Private Sub Update_Click
    Dim i  As Int
    Try
        Dim SmallPanel As Panel
        Dim SmallLable As Label       
        For i=2 To 4    'CLV1.Size-1
            SmallPanel = CLV1.GetPanel(i)
            SmallLable = SmallPanel.GetView(1)
            SmallLable.Text = "Value : " & i
        Next
    Catch
        ToastMessageShow ( LastException, True)
    End Try
End Sub

Any help please,
Thanks on advance for any help
Best regards
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
It's going to be impossible for anyone here to help you unless you specify what error you are getting, or if no error what behavior is happening that is unexpected to you.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Try puting the Dim panel and Dim label inside the loop.

I would guess all the labels ended up showing 'Value 4"
 
Last edited:
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Dear Mr. Jeffrey :
The error message is as :
java.lang.RuntimeException: Object should first be initialized (View).

thanks Mr. Daestrum :
I made (puting the Dim panel and Dim label inside the loop.) but not work
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Sorry I should have been clearer

B4X:
    Try
        For i=2 To 4    'CLV1.Size-1
            Dim SmallPanel As Panel = CLV1.GetPanel(i)
            Dim SmallLable As Label = SmallPanel.GetView(1)
            SmallLable.Text = "Value : " & i
        Next
    Catch
        ToastMessageShow ( LastException, True)
    End Try
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
Sorry I should have been clearer

B4X:
    Try
        For i=2 To 4    'CLV1.Size-1
            Dim SmallPanel As Panel = CLV1.GetPanel(i)
            Dim SmallLable As Label = SmallPanel.GetView(1)
            SmallLable.Text = "Value : " & i
        Next
    Catch
        ToastMessageShow ( LastException, True)
    End Try
I tested it, it still not run and gave same error
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Assuming you have at some point loaded items into the CLV1, is your label the 2nd view contained in your panel? The line
B4X:
Dim SmallLable As Label = SmallPanel.GetView(1)
will load the second view contained in the "SmallPanel" panel.
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
I work on this example :

Just I need to modify label "This is item #." into different values in the running say after click in any button.
Best regards
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
I got solution, thanks Mr. Jeffrey

this is the solution with minor modifications.

Best regards
 
Upvote 0
Top