Android Question Drawable progressbar problem

Fillmore

Member
Licensed User
Longtime User
Hi guys,

I don't understand why it doesn't work....

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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

End Sub
Sub Globals
  Dim pb1,pb2,pb3,pb4 As ProgressBar
  Dim pb() As ProgressBar
End Sub
Sub Activity_Create(FirstTime As Boolean)
 
 
 
 
  Activity.LoadLayout("test")
 
  pb = Array As ProgressBar(pb1, pb2, pb3, pb4)
 
  For i=0 To 3
  pb(0).Initialize("pb")
  Next
 
 
  Dim gd As GradientDrawable
  gd.Initialize("TOP_BOTTOM", Array As Int(Colors.green, Colors.green))
gd.CornerRadius = 3dip
  Dim cd As ColorDrawable
  cd.Initialize(Colors.black, 3dip)
 
  For i = 0 To 3
  SetProgressDrawable(pb(i), gd, cd)
  pb(i).Progress = 50
  Next

 
 
 
  Activity.AddView(pb(0), 10dip, 10dip, 90dip, 10dip)
  Activity.AddView(pb(1), 30dip, 10dip, 90dip, 10dip)
  Activity.AddView(pb(2), 50dip, 10dip, 90dip, 10dip)
  Activity.AddView(pb(3), 80dip, 10dip, 90dip, 10dip)
 
       
   
   
   
   
   
End Sub

Sub SetProgressDrawable(p As ProgressBar, drawable As Object, backgroundDrawable As Object)
  Dim r As Reflector
  Dim clipDrawable As Object
  clipDrawable = r.CreateObject2("android.graphics.drawable.ClipDrawable", _
      Array As Object(drawable, Gravity.LEFT, 1), _
      Array As String("android.graphics.drawable.Drawable", "java.lang.int", "java.lang.int"))
  r.Target = p
  r.Target = r.RunMethod("getProgressDrawable") 'Gets the layerDrawable
  r.RunMethod4("setDrawableByLayerId", _
      Array As Object(16908288, backgroundDrawable), _
      Array As String("java.lang.int", "android.graphics.drawable.Drawable"))
  r.RunMethod4("setDrawableByLayerId", _
      Array As Object(r.GetStaticField("android.R$id", "progress"), clipDrawable), _
      Array As String("java.lang.int", "android.graphics.drawable.Drawable"))
End Sub


Thanks a lot !

Good evening.

Fred
 

Fillmore

Member
Licensed User
Longtime User
Ok sorry.

Error :

on line 71 : r.Target = p ==>(Object should first be initialized (progress bar)


I don't know what's wrong... Just the appli is not running.


Thanks a lot.

Fred
 

Attachments

  • progress draw.zip
    7.1 KB · Views: 259
Upvote 0

NJDude

Expert
Licensed User
Longtime User
This loop:
B4X:
For i=0 To 3
    pb(0).Initialize("pb")
Next
Should be:
B4X:
  For i=0 To 3
  pb(i).Initialize("pb")
Next

and you have to change the TOP of each ProgressBar or you will only see one, the code should be:
B4X:
Activity.AddView(pb(0), 10dip, 10dip, 90dip, 10dip)
Activity.AddView(pb(1), 10dip, 30dip, 90dip, 10dip)
Activity.AddView(pb(2), 10dip, 50dip, 90dip, 10dip)
Activity.AddView(pb(3), 10dip, 70dip, 90dip, 10dip)
 
Upvote 0
Top