Issues w loadlayout and addsingleline

nemethv

Member
Licensed User
Longtime User
hi,

I have made a layout in the Designer and am trying to put values into a list that is in the designer and is called StationList (type is listview). However, if I'm using the code below, I get a view doesn't exit error.

B4X:
Sub Activity_Create(FirstTime As Boolean)

   Dim StationList As ListView
   Dim StationCount As Int
   Dim i As Int
    
   
   Dim dir As String
   dir = CopyDBFromAssets("lineinfo.db")
   SQL1.Initialize(dir,"lineinfo.db",True)

   
   StationList.Initialize("StationList")
   
   StationList.SingleLineLayout.Label.TextColor = Colors.Black

   Activity.Color = Colors.white
   Activity.LoadLayout("StationFreeSearch")    'this is the layout where the list is
   
   StationCount = SQL1.ExecQuerySingleResult("SELECT count(DISTINCT StationName) FROM lineinfo")
   For i = 1 To StationCount
      StationList.AddSingleLine(SQL1.ExecQuerySingleResult("SELECT DISTINCT StationName FROM lineinfo WHERE StationAlphaID = " & i )) 'the query is okay in terms of there are no errors in the sql part, but the list remains completely empty. 
   Next 
      

   Activity.LoadLayout("StationFreeSearch")
   'Activity.AddView(StationList, 0, 0, 100%x, 100%y) /* im not using these because this doesnt actually utilise the layout. */
   'Activity.AddView(Searchbox, 0, 0, 300dip, 100dip) /* ignore this for now */
End Sub

What am I doing wrong?
Also I'll probably have another query related to using an autocomplete box and shrinking down the list according to what's typed in the box once this gets sorted :)
Thanks!
 

eps

Expert
Licensed User
Longtime User
Have you stepped through the code? Is it getting data from the DB as you expect?

Is the ListView visible? Did you add this in the designer? Is it set up correctly?
 
Upvote 0

nemethv

Member
Licensed User
Longtime User
I think this :

B4X:
  For i = 1 To StationCount

should be

B4X:
  For i = 0 To StationCount - 1


No, that's not the problem. It is getting data as expected (when stepping through) and if I use the "'Activity.AddView(StationList, 0, 0, 100%x, 100%y)" line then it works but it doesn't load the layout from the designer, which is the one I want as I've set it up for the various screen sizes. I remember reading somewhere that layouts defined in the designer need to be handled in some odd way but I don't remember how precisely.
 
Upvote 0

nemethv

Member
Licensed User
Longtime User
As the StationList ListView is defined in the Designer you must remove this line.
B4X:
StationList.Initialize("StationList")
Best regards.

The line
B4X:
StationList.AddSingleLine(SQL1.ExecQuerySingleResult("SELECT DISTINCT StationName FROM lineinfo WHERE StationAlphaID = " & i ))

Produces an error saying object should first be initialized(listview).
Sorry, I'm more used to standard VBA, this is a little new for me :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Couldn't you post your project as a zip file (IDE menu Files / Export As Zip) ?
So we could see what you have done and how and give you a concrete answer.
Otherwise we need to try to guess what you could have done wrong.

Best regards.
 
Upvote 0

nemethv

Member
Licensed User
Longtime User
Couldn't you post your project as a zip file (IDE menu Files / Export As Zip) ?
So we could see what you have done and how and give you a concrete answer.
Otherwise we need to try to guess what you could have done wrong.

Best regards.

Ahh stupid me. I had the Activity.LoadLayout twice in the script and that caused some odd issues.
I'll probably come back with another question soon though (searchbox related)
Thanks for your help.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
No, that's not the problem. It is getting data as expected (when stepping through) and if I use the "'Activity.AddView(StationList, 0, 0, 100%x, 100%y)" line then it works but it doesn't load the layout from the designer, which is the one I want as I've set it up for the various screen sizes. I remember reading somewhere that layouts defined in the designer need to be handled in some odd way but I don't remember how precisely.

but it will cause you other issues...
 
Upvote 0
Top