Android Question list with one item

apty

Active Member
Licensed User
Longtime User
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?
 

DonManfred

Expert
Licensed User
Longtime User
check for existence of a ;
If no one exists and the string is not empty then it is only one Item.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i already have an if else statement that checks if it single item, then it does as below if there's only one item:
B4X:
        If listd.Size=1 Then
        Dim components() As String
        components = Regex.Split(";", listd.Get(0))
        lblNameVer.Text=components(0)
This however still doesn't work. If i log the item, i can see it, but if i assign to the label as shown above, it is not displaying
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Dim lblNameVer As Label 'this is also loaded with the designer, so i did not initialize
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?
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
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
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
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
 
Upvote 0
Top