when click button show loading dialog box in monodroid?


Ask by : Saeed Hashemi November 04, 2012 06:05

I want to show loading prompt when click button ,how can i do that?

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);
        objListView = FindViewById<ListView>(Resource.Id.listView1);
        button.Click += button_Click;
    }

    void button_Click(object sender, EventArgs e)
    {
     //in this place i get RSS list from web ,this process take a minute 
    }
View original question

Answer by : Omid MafakherNovember 04, 2012 06:04

first, you need to add a variable in for loading progress

private ProgressDialog progress;

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            Button button = FindViewById<Button>(Resource.Id.MyButton);
            objListView = FindViewById<ListView>(Resource.Id.listView1);

            button.Click += (s, e) => {
                Action act = new Action(YOUR METHOD NAME);
                progress = new ProgressDialog(this);
                progress.SetTitle("loading...");
                progress.Show();

                act.BeginInvoke(a => act.EndInvoke(a), null);
            };
        }

and in your method you have to dismiss loading progress

progress.Dismiss();
View original answer