Android Question Need help with SecondLabel.Text in a ListView

GMan

Well-Known Member
Licensed User
Longtime User
I have a ListViewNummern with 2 Labels - both with text only.
Now i want to read out the SecondLabel.Text, but always shows me this exception:
B4X:
(NumberFormatException) java.lang.NumberFormatException: empty String

Here is my code for this part:

B4X:
Private Sub ListViewNummern_ItemClick (Position As Int, Value As Object)
    Dim Vally As String

    Try
        Vally = ListViewNummern.GetItem(ListViewNummern.TwoLinesAndBitmap.SecondLabel.Text)
        Log("Vally: " & Vally)
    Catch
        Log(LastException)
    End Try
End Sub

But I can see the content of the secondlabel in my ListView - so why is there this error ?
 

Sagenut

Expert
Licensed User
Longtime User
GetItem expect an Int as parameter.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I am not using Listview by long time.
I would need to make some test but I will be able to do something only in the afternoon.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You already have the value from the sub
you prob need to have something like (not tested)
B4X:
...
dim items(2)  as  Label = Value
Vally = items(1).text
 
Upvote 0

PaulMeuris

Active Member
Licensed User
In this CLV solution the CustomListView item consists of a checkbox and a label.

The order of the views in the designer (or when adding by code) determines the index number of the GetView method.
Each item of a CLV has a default panel even if it's not present in the designer or when you use the AddTextItem method.
This code shows how to use the properties of the checkbox and the label:
CLV itemclick:
Private Sub clv1_ItemClick (Index As Int, Value As Object)
    If clv1.GetPanel(Index).GetView(0).Checked = False Then
        clv1.GetPanel(Index).GetView(0).Checked = True    ' change the property Checked
        Log(clv1.GetPanel(Index).GetView(1).Text)        ' the value of the label text
    End If
End Sub
You can of course only use the properties that are available for that view type: a checkbox has a Checked property, a label has a Text property.
The Value parameter contains the value that was used to add an item to the CLV as in:
B4X:
    For i = 0 To 4
        Dim pnl As Pane = set_clv1_item("clvitem_layout",i,names.Get(i))
        clv1.Add(pnl,i)    
    Next
In this case the Value parameter is equal to the index of the item in the CLV (0 to 4).
This explanation is of course for a CustomListView.
And for the not recommended use of a ListView (and stated by @teddybear):
B4X:
    ListView1.AddTwoLines2("text 1","text 2","text 2")
   
Private Sub ListView1_ItemClick (Position As Int, Value As Object)
    Log(Position)
    Log(Value)
    Log(ListView1.GetItem(Position))    ' return value set to the second line
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…