• We just launched and are currently in beta. Join us as we build and grow the community.

Android Progressbar Tutorial using Basic4Android

iCheri

Cosplayer
I Rep
0
0
0
Rep
0
I Vouches
0
0
0
Vouches
0
Posts
172
Likes
189
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Hi! In this tutorial, I will introduce another component/controls in Basic4Android, the ProgressBar. ProgressBar displays a bar to the user representing how far the operation has progressed; the application can change the amount of progress modifying the length of the bar as it moves forward.

On this, you need to create one ProgressBar and named it as "pgb1", two Labels and named it as "lblPercent" for the percentage, and "Label1" and label it as "%". Next, named your abstract design as "tutorial". Your abstract designer will be like this one below:

progrssbarimage.png


Declare your variable in the Sub_Global like this:
  1. Sub

    Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4. Dim

    timer1 As

    Timer
  5. Dim

    pgb1 As

    ProgressBar
  6. Dim

    num As

    Int
  7. Dim

    lblPercent As

    Label
  8. End

    Sub

Note:

timer1 - our variable used for the Timer. We need timer to determine the increasing progress of our ProgressBar. Timer schedules one-shot or recurring tasks for execution.
pgb1 - our variable for our ProgressBar.
num - we used num as an integer to increment the value of the ProgressBar that complements in time.
lblPercent - this is our variable for our Label to display the number in percentage of the ProgressBar.

Next, Declare the Timer and its method name Tick.
  1. Sub

    timer1_Tick
  2. num = num + 1
  3. pgb1.Progress = num
  4. lblPercent.Text = num
  5. If

    num > 100 Then
  6. timer1.Enabled=False
  7. Msgbox(""

    ,"Completed"

    )
  8. pgb1.Visible=False
  9. End

    If
  10. End

    Sub

Note:

timer1_Tick

- timer1 here is our control and its method name is Tick in which it defines that the timer will now start.
num = num + 1

- num is declared to increment its value by 1.
pgb1.Progress = num

- the value of our progressbar will be equal to the incrementation of our num.
lblPercent.Text = num

- the value of our lblPercent as Label will be equal to the incrementation of our num in number.

  1. If

    num > 100 Then
  2. timer1.Enabled=False
  3. Msgbox(""

    ,"Completed"

    )
  4. pgb1.Visible=False
  5. End

    If

Note:

If our variable num will reach at 99, then our timer will be disabled and it will display "Completed". Also, our ProgressBar will be vanished.

Now, We will create our Activity_Create:
  1. Sub

    Activity_Create(FirstTime As

    Boolean

    )
  2. 'Do not forget to load the layout file created with the visual designer. For example:
  3. Activity.LoadLayout("tutorial"

    )
  4. timer1.Initialize("timer1"

    ,400)
  5. timer1.Enabled=True
  6. End

    Sub

Note:

Activity.LoadLayout("tutorial"

)

- the named tutorial here is the design in which we created in the abstract designer.
timer1.Initialize("timer1"

,400)

- we initialized our timer as the named of timer1 and the 400 here is the time interval in milliseconds.
timer1.Enabled=True

- we initialized our timer to be enabled to perform its action.

Here's the full code of this tutorial:
  1. Sub

    Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.

  4. End

    Sub

  5. Sub

    Globals
  6. 'These global variables will be redeclared each time the activity is created.
  7. 'These variables can only be accessed from this module.
  8. Dim

    timer1 As

    Timer
  9. Dim

    pgb1 As

    ProgressBar
  10. Dim

    num As

    Int
  11. Dim

    lblPercent As

    Label
  12. End

    Sub

  13. Sub

    Activity_Create(FirstTime As

    Boolean

    )
  14. 'Do not forget to load the layout file created with the visual designer. For example:
  15. Activity.LoadLayout("tutorial"

    )
  16. timer1.Initialize("timer1"

    ,400)
  17. timer1.Enabled=True
  18. End

    Sub
  19. Sub

    timer1_Tick
  20. num = num + 1
  21. pgb1.Progress = num
  22. lblPercent.Text = num
  23. If

    num > 100 Then
  24. timer1.Enabled=False
  25. Msgbox(""

    ,"Completed"

    )
  26. pgb1.Visible=False
  27. End

    If
  28. End

    Sub
  29. Sub

    Activity_Resume
  30. End

    Sub

  31. Sub

    Activity_Pause (UserClosed As

    Boolean

    )
  32. End

    Sub

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09126450702
E-mail:[email protected]

Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top