GMan Well-Known Member Licensed User Longtime User Oct 5, 2024 #1 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 ?
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 Oct 5, 2024 #2 GetItem expect an Int as parameter. Upvote 0
GMan Well-Known Member Licensed User Longtime User Oct 5, 2024 #3 Sagenut said: GetItem expect an Int as parameter. Click to expand... So how to get the "Value" ? The "normal" Value contents the first Label.Text Upvote 0
Sagenut said: GetItem expect an Int as parameter. Click to expand... So how to get the "Value" ? The "normal" Value contents the first Label.Text
Sagenut Expert Licensed User Longtime User Oct 5, 2024 #4 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
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.
Sagenut Expert Licensed User Longtime User Oct 5, 2024 #5 Check this https://www.b4x.com/android/forum/threads/listview-reading-second-line.7059/post-40547 Upvote 0
teddybear Well-Known Member Licensed User Oct 5, 2024 #6 GetItem (Index As Int) As ObjectReturns the value of the item at the specified position. Returns the "return value" if it was set and if not returns the text of the first line. Upvote 0
GetItem (Index As Int) As ObjectReturns the value of the item at the specified position. Returns the "return value" if it was set and if not returns the text of the first line.
Daestrum Expert Licensed User Longtime User Oct 5, 2024 #7 You already have the value from the sub you prob need to have something like (not tested) Code: ... dim items(2) as Label = Value Vally = items(1).text Upvote 0
You already have the value from the sub you prob need to have something like (not tested) Code: ... dim items(2) as Label = Value Vally = items(1).text
P PaulMeuris Well-Known Member Licensed User Oct 6, 2024 #8 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: Code: 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: Oct 6, 2024 Upvote 0
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: Code: 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