Hi
        Problem 1 : Showing a Progress Bar

        I am doing everything programatically You can also use axml to do this.

        Declare the folowing globally in your activity.

        static bool showActivity =false;
        ProgressBar _activityIndicator;
        private static System.Timers.Timer _periodicTimer ;

        In the OnCreate method or where you initialise you views do
the following

           _activityIndicator = new ProgressBar(this);
           _activityIndicator.Visibility = ViewStates.Invisible;
           RelativeLayout.LayoutParams
activityProgressAnimationParams = new RelativeLayout.LayoutParams(100,
100);
           
activityProgressAnimationParams.AddRule(LayoutRules.CenterHorizontal);
           activityProgressAnimationParams.AddRule(LayoutRules.CenterVertical);
           [relativeLayout].AddView(_activityIndicator,
activityProgressAnimationParams);

           I am adding this to a RelativeLayout View. You may need to
adjust this to what ever is
           your main Layout.

           Alternative if you have declared this in axml, you can do
the following,

          _activityIndicator =
FindViewById<ProgressBar>(Resource.Id.progressBar)

           Also initialise the Periodic Timer
            _periodicTimer = = new System.Timers.Timer();
            _periodicTimer.Elapsed += new
ElapsedEventHandler(PeriodicTimer_Tick);
           _periodicTimer.Interval = 500;
           Optionally you can start this Timer Now
_periodicTimer.Start(); or only when you need

         Declare the Period Timer Event Handler
       private void PeriodicTimer_Tick(object sender, ElapsedEventArgs e)
       {
            RunOnUiThread(delegate()
            {
                  if (showActivity ==true)
                 {
                             _activityIndicator.Visibility = ViewStates.Visible;
                  }else
                 {
                     _activityIndicator.Visibility = ViewStates.Invisible;
                      _activityIndicator.Visibility = ViewStates.Gone;
                     Optionally you can stop the Timer
_periodicTimer.Stop();
                 }
            });
       }

       When ever you want to show a long running activity in executing
in another thread
       you can just enclose it in showActivity =true and showActivity=false.

       You can execute like this
           showActiivity =true
           ThreadPool.QueueUserWorkItem(o =>
            {
                try
                {
                       WXclass5.getwindmap(ds, WXclass5.altsel.ToString());
                       showActivity =false;
                }
                catch (Exception ex)
                {
                    ShowMessage("Start Application + [" + ex.Message +
"]", "ERROR");
                }
           });

          ShowActivity=false should be within the running thread and
not from the calling thread.

          You should be able to put a breakpoint in your code. I have
been using visual studio and able to put a break point.

          Hope this helps

Best Regards,
Sridharan Srinivasan
Alias Sri.

On Sat, Sep 17, 2011 at 6:32 PM, John Murray <j...@murray.gb.com> wrote:
> I’ve cracked a number of things along the learning curve of Mandroid but I
> am being really thick here
>
> I just cannot get my head around the implementation of a progress bar – can
> some kind soul help  me with some idiot proof code?
>
>
>
> I have a static class method which fetches some meteorological diagrams from
> a webserver and places resulting bitmap in a static  which is later accessed
> by an imageview
>
> Takes 4 or 5 seconds but a lot longer over a GSM network therefore I want to
> put up a progress thingy
>
>
>
> For the time being I’ve got a textview just saying loading
>
>
>
> These lines of code are called  when a user selects something  from a
> spinner
>
> Obviously this doesn’t do much
>
>  t1.Text = "loading";
>
>                      WXclass5.getwindmap(ds, WXclass5.altsel.ToString());
>
>                 t1.Text = "";
>
> but why cant I do this
>
> t1.Text = "loading";
>
>                      ThreadPool.QueueUserWorkItem(o
> =>WXclass5.getwindmap(ds, WXclass5.altsel.ToString()));
>
>                 t1.Text = "";
>
> there’s no UI code in the ‘getwindmap’ – just a webclient call and some
> bitmap/byte manipulation
>
> but implementing the threadpool.QueueWorkItem does not seem to fetch
> anything or do anything – I can’t seem to debug into it to see what’s
> happening (is there a special method of debugging on separate threads?
>
>
>
> With regards to implementing the progress bar instead of text saying loading
>  I presume I just replace the text.t1 with a progressbar  -and set it
>  visible  before the threadpoolqueue and non-visible after?
>
>
>
> I suspect it is not that simple
>
>
>
> Sorry to seem so  stupid but I’ve read all the android stuff on progressbars
> and I’ve developed a complete mental block – the more I read the less I
> understand.
>
> Can someone please explain in baby language please?
>
>
>
>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>
>



-- 
Sridharan Srinivasan
Alias Sri
Ph:(65)98255785/(65)63922439
www.arshu.com
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to