Android Question Problems Populating a Scrollview

I am a newbie and have been evaulating b4a using the trial version. I'm having real problems with try to read in a csv, sort on a field and then populate a scrollview with the field "Name". I've never in my life resorted to asking on a forum but am tearing my hair out. Would anyone be so kind as to tell me what I'm doing wrong - pretty please. Many thanks, Nigel
 

Attachments

  • Pegboard.zip
    14.6 KB · Views: 264
Thanks for looking into this Erel.

Unfortunately:
  • changing 1 to 0 didn't solve the problem though it was a mistake by me
  • I don't understand how to use the For Each Item() method
  • Since I'm evaluating B4A I can't download the CustomListView files

Can you see why my current code doesn't work? Thanks for you time.

Kind regards, nigel
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can you see why my current code doesn't work?
Always post the error message when something is not working.

Each item in lstPlayers is a tPlayers object. This code is wrong:
B4X:
Dim cells() As String
cells = lstPlayers.get(i)
It should be:
B4X:
Dim player As tPlayers = lstPlayers.Get(i)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had a look at your program and have following comments:

1. It seems to me that you are not using the Headers of the csv file, so you could use
ToSort = su.LoadCSV2(File.DirAssets, "players.csv", ",")
instead of
ToSort = su.LoadCSV2(File.DirAssets, "players.csv", ",", Headers)

I would suggest you to remove the first entry in your csv file to avoid the need to skip it and then use:
For i = 0 To ToSort.Size - 1
instead of
For i = 1 To ToSort.Size - 1

2. The problem you encounter is here:
Dim cells() As String
cells = lstPlayers.get(i)


You fill lstPlayers with a Type variable for each entry.
So you need to change it to:
Dim Player As tPlayer
Player = lstPlayers.get(i)


and then use
lbl1.Text = Player.Name
If Player.Sex="M" Then


instead of
lbl1.Text = cells(0)
If cells(1)="M" Then


3. You need to replace
svPlayers.Panel.AddView(lbl1, 100, height * i, 120dip, height)
by
svPlayers.Panel.AddView(lbl1, 100dip, height * i, 120dip, height)
you must use dip values.

4. You need to change your layout files.
You use the 'standard' screen size 320 x 480, scale 1.
But the views go beyond these limits for a bigger screen.
I suggest you to read the relevant chapters about screen sizes and layouts in the Beginner's Guide.

Attached a modified project, but without any layout change.
 

Attachments

  • Pegboardv11.zip
    5.6 KB · Views: 287
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Upvote 0
You've all been very helpful!! I'm trying to get an Excel app that I wrote (http://pegboard4free.com/www-pegboard4free-com/) into an Android app that I can distribute for free. I need to make sure B4A will work for me as I won't be getting any money for this as it's just a hobby and £50 is a lot for what will be a single app.

However, if this degree of help is typical then I am far more confident in going for B4A!

As people come along to a club night of badminton or tennis they get ticked and there name goes into another box. When players go onto court their names go into another box. When the game ends the results get stored and the players' results get updated in lstPlayers and so forth. At the end of the night the CSV file gets updated. The main part which should tranfer intoo B4A fine is about picking fair games with everyone getting equal court time. Sorry to bore you but can you describe how a CLV might be better than a ScrollView.

PS Erel sorry I didn't put an error decription in my message but it just bombed out and I got no message!

Thanks again, Nigel
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Instead of using a csv file I would suggest to use a SQLite database.
Databases are by far not that complicated.
There is a whole chapter about SQLite in the B4A User's Guide with example projects.

ScrollView versus CustomListView?
CustomListView is based on a ScrollView but has build in facilities for the entries layouts, you can have different layouts for different entries.
For 'simple' entries like in your project I would use a ScrollView, but this is my personal point of view.
 
Upvote 0
I'm getting bit nervous with so many new things (SQLite, screen size adjustments, B4A) ;-)
Thanks for your advice and will look into SQLite.

Regarding my scrollview, I am populating it with:

B4X:
    For i = 0 To lstPlayers.Size-1
        Dim player As tPlayers = lstPlayers.Get(i)
        Dim chk As CheckBox
        chk.Initialize("chkPlayers")
        lstChecks.Add(chk)
        Dim lbl1 As Label
        lbl1.Initialize("")
        lbl1.Text =player.Name
        lbl1.TextSize=20
        lbl1.Gravity = Gravity.CENTER_VERTICAL
        If player.Sex="M" Then
            lbl1.TextColor = Colors.cyan
        Else
            lbl1.TextColor = Colors.RGB(255,209,220)
        End If
        svPlayers.Panel.AddView(chk, 0, height * i, 120dip, height)
        svPlayers.Panel.AddView(lbl1, 50dip, height * i, 120dip, height)
    Next

and can detect a click with:

B4X:
Sub chkPlayers_Click
   
End Sub

but could you tell me how to add the persons name to a scrollview on another tab and add the persons name, sex etc to another array that can hold the persons details (eg games won, lost etc) until the end of the badminton session when the db or csv is updated.

Sorry to be so needy at the moment but once I get these couple of basic methods sorted I think I'll be ok. I'm finding the examples a bit elaborate and can't seem to find ones that quite work for me. When you know a subject well you can find out things easy as you can google the right questions, but as a newbie it takes that much longer so many thanks for your help!

Kind regards, Nigel
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm finding the examples a bit elaborate and can't seem to find ones that quite work for me.
Which examples are you speaking of?
I am afraid that you will nerver find any code examples fitting the needs you expect.

When you know a subject well you can find out things easy as you can google the right questions, but as a newbie it takes that much longer so many thanks for your help!
We all were newbies here one day!
My only advice, learn > test > learn > test etc.

Learning a new language and/or a new operating systems needs some time to learn and get used to it.
Not that long ago a had never used any database, then I wanted to use them and studied SQLite, my experience is in the User's Guide.
The management of the different screen sizes is not really easy, you need to understand how Android works, and use the Designer with Anchors and DesignerScripts.
It also depends on what devices you want your application to run on, only small screen sizes (phones) or only big screnn sizes (tablets) or both and what you want to dispay on a small screen or a bigger screen at the same time.
This shows that it is not possible to give general rules, you need to learn and understand what's happening, there are no 'magic' functions doing everything for you.
But, the DesignerScripts and Anchores are very usefull.
 
Upvote 0
Again, thanks!

I've tried to use SQLite but the program doesn't get past this point and no error message is given:

B4X:
Cursor1 = SQL1.ExecQuery("SELECT ID FROM players")

Don't worry if no time, you've helped enough as it is, but if you take pleasure out of helping then great!!

Kind regards, Nigel
 

Attachments

  • Pegboard.zip
    17.5 KB · Views: 259
Upvote 0
Klaus, I really appreciate your help but it crashes on the following line with no error message:

B4X:
ResultSet1 = SQL1.ExecQuery("SELECT ID FROM players")

I'm confused as to how it can work for you but not me. Maybe it's just me!
 
Upvote 0
Top