in my app, i create a list by adding items from a table in an online db. I then show these items in my app (its an image and a label). Sometimes the table has only one item, though this item is added in the list, it is not shown in my app.
B4X:
For i=0 To listd.Size-1
Dim components() As String
components = Regex.Split(";", listd.Get(i))
log(components(0))'the log here displays properly
Dim lblNameVer As Label 'this is also loaded with the designer, so i did not initialize
lblNameVer.Text=components(0)'this does not show if there's one item in the list, it only shows if i have more than 1 item
Next
How can i display the item even if the list has one item only?
IMHO you shouldn't redim it. If it's part of the layout why you dim it anew (probabily causing the existence of a new local variable which has no representation on the layout space)?
Another point: are you sure that a single item list is terminated by a semicolon?
there could be more than one label in cases where i have more than 1 item,and i need reference to these labels. Dimming doesn't have any problem as the items are displayed if they're more than one. Even if i remove dim, it still does not show if there's one item
This works for me every time. I checked it by creating a tiny project, unless you are talking about something over my head :
B4X:
Activity.LoadLayout("Layout1") 'has 1 label
Dim listd As List
listd.Initialize
listd.Add("Erel;klaus")
If listd.Size=1 Then
Dim components() As String
components = Regex.Split(";", listd.Get(0))
lblNameVer.Text=components(0) 'displays: Erel
End If
For i=0 To listd.Size-1
Dim components() As String
components = Regex.Split(";", listd.Get(i))
Log(components(0))'the log here displays properly
lblNameVer.Text=components(0)'this does not show if there's one item in the list, it only shows if i have more than 1 item
Next