Help woth the Controls

mebcs

Member
Licensed User
Longtime User
:sign0104: Day 1 for me with b4a. Be kind.

I have the following code. It runs but I dont see the progress bar change or the list display any values.

Sub Globals
Dim PBar As ProgressBar
Dim PIDLst As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
ToastMessageShow ( "Welcome",False)
Activity.LoadLayout("main")

PBar.Initialize ("PBar")
PIDLst.Initialize("PIDLst")
PIDLst.SingleLineLayout.ItemHeight = 100dip
Dim PIDLabel As Label
PIDLabel = PIDLst.SingleLineLayout.Label
PIDLabel.TextSize = 10
PIDLabel.TextColor = Colors.Red
PIDLabel.Gravity = Gravity.CENTER
For i = 1 To 100
PIDLst.AddSingleLine("NetworkID::BranchID::00" & i)
PBar.Progress =100
Next
ToastMessageShow ( "Data Loaded",False)
End Sub
 

NJDude

Expert
Licensed User
Longtime User
Welcome to B4A!!!

Ok, a few things, first, when you post code you better enclose it using the [ code] ... [/ code] tags or upload your project, to do that open the designer, then click on File --> Export as ZIP.

Looking at your code I see some issues, these 2 lines:
B4X:
PBar.Initialize("PBar")
PIDLst.Initialize("PIDLst")

If you have created the views in the designer you DON'T have to initialize them, you only do that when you create them programmatically.

Posting the full source would help us to help you. ;)
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
Your PIDLst is being generated with the data you are telling it to use. NetworkID::Branch...etc, etc. As for the progress. You are setting the bar to 100 which shows it as complete.

B4X:
PBar.Progress = 100

Means the progress is set at 100 percent. You would need to have it setup like:

B4X:
PBar.Progress = PBar.Progress + 1

Also, your code is being generated very quickly so the progress bar will always be full. Just to show you that it works add this:

B4X:
Sub Pause(Wait As Int)
   Dim TheTime As Long
   TheTime= DateTime.Now + (Wait * 1000)
   Do While DateTime.Now < TheTime
      DoEvents
   Loop
End Sub

Then put the pause sub in your code like this:

B4X:
For i = 1 To 100
      Pause(1)
      PIDLst.AddSingleLine("NetworkID::BranchID::00" &  i)    
      PBar.Progress = PBar.Progress + 1
   Next

It will add a record every second and build the list slowly. You will be able to see the progress bar in action by doing this. Something that loads extremely quick like this though probably doesn't need a progress bar. Just a simple "Load Complete" should be sufficient.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Just a note:
B4X:
Sub Pause(Wait As Int)

   Dim TheTime As Long

   TheTime= DateTime.Now + (Wait * 1000)

   Do While DateTime.Now < TheTime
      DoEvents
   Loop

End Sub

The code above is a "bad Android programming approach" is better to use a timer and process the data there.
 
Upvote 0

PharCyDeD

Active Member
Licensed User
Longtime User
How is it bad to add a simple delay like that? I guess I don't understand what a timer does that is better? How would you use a timer to create a pause?
 
Upvote 0
Top