2012-11-04 39 views
1

我想單擊按鈕時顯示加載提示,我該怎麼做?單擊按鈕顯示monodroid中的加載對話框?

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 
    } 

回答

1

首先,你需要在添加一個變量加載進度

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); 
      }; 
     } 

,並在你的方法,你必須摒棄加載進度

progress.Dismiss(); 
相關問題