3
Answers

Xamarin Progress Bar c#

balaji palani

balaji palani

8y
419
1
 
I have made a ProgressDialog that should appear immediately before a web service call or some data loading in Button click event
  
 
Please see below codes,
 
  1. addTask = FindViewById<Button>(Resource.Id.myButton);  
  2. addTask.Click += (sender, e) => {  
  3.                   
  4.                 progress = new Android.App.ProgressDialog(this);  
  5.                 progress.Indeterminate = true;  
  6.                 progress.SetProgressStyle(Android.App.ProgressDialogStyle.Spinner);  
  7.                 progress.SetMessage("Loading... Please wait...");  
  8.                 progress.Show();  
  9.   
  10. XmlSerializer xm=new XmlSerializer(typeof(n107_180_68_111.BizInfoFinderSearchResults));  
  11.                   
  12.                 StringWriter writer = new StringWriter();  
  13.                 xm.Serialize(writer, result1);  
  14.                 string xmlContent = writer.ToString();  
  15. XmlDocument doc = new XmlDocument();  
  16.                 doc.LoadXml(xmlContent);  
  17.                 doc.Save(Console.Out);  
  18.                 try  
  19.                 {  
  20.   
  21.   
  22.                     XmlNodeList siteResults = doc.GetElementsByTagName("SiteResults");  
  23.   
  24.                     bool titleRow = true;  
  25.   
  26.                     if (!object.ReferenceEquals(siteResults, null))  
  27.                     {  
  28.                         XmlNodeList siteSearchResults = siteResults[0].ChildNodes;  
  29.                         int count = siteSearchResults.Count;  
  30.                         for (int i = 0; i < count; i++)  
  31.                         {  
  32.                             if (!object.ReferenceEquals(siteSearchResults, null))  
  33.                             {  
  34.                                 foreach (XmlNode siteSearchResult in siteSearchResults)  
  35.                                 {  
  36.                                     if (siteSearchResult.InnerText != null)  
  37.                                     {     
  38.                                         string siteID = siteSearchResult.ChildNodes[0].InnerText.Trim();  
  39.                                         int totalhits = Convert.ToInt32(siteSearchResult.ChildNodes[5].InnerText.Trim());  
  40.                                         XmlNode results = siteSearchResult.ChildNodes[7];  
  41.                                         titleRow = true;  
  42.                                         finalResults[i] = new DataTable();  
  43.                                         if (!object.ReferenceEquals(results, null))  
  44.                                         {  
  45.                                             int rowIndex = 0;  
  46.   
  47.                                             foreach (XmlNode result in results.ChildNodes)  
  48.                                             {  
  49.                                                 if (titleRow)  
  50.                                                 {  
  51.                                                     foreach (XmlNode col in result.ChildNodes)  
  52.                                                     {  
  53.                                                         finalResults[i].Columns.Add(col.InnerText.Trim());  
  54.                                                     }  
  55.                                                     finalResults[i].Columns.Add("SiteID");  
  56.                                                     finalResults[i].Columns.Add("TotalHits");  
  57.                                                     titleRow = false;  
  58.                                                 }  
  59.                                                 else  
  60.                                                 {  
  61.                                                     if (rowIndex > 0)  
  62.                                                     {  
  63.                                                         int colIndex = 0;  
  64.                                                         DataRow row = finalResults[i].NewRow();  
  65.   
  66.                                                         foreach (XmlNode col in result.ChildNodes)  
  67.                                                         {  
  68.                                                             row[colIndex] = col.InnerText.Trim();  
  69.                                                             colIndex++;  
  70.                                                         }  
  71.                                                         row[colIndex] = siteID;  
  72.                                                         row[colIndex + 1] = totalhits;  
  73.                                                         finalResults[i].Rows.Add(row);  
  74.                                                     }  
  75.                                                 }  
  76.                                                 rowIndex++;  
  77.                                             }  
  78.                                         }  
  79.                                         i++;  
  80.                                     }  
  81.                                     else  
  82.                                     {  
  83.                                         count--;  
  84.                                     }  
  85.                                 }  
  86.   
  87.   
  88.   
  89.                                 for (int j = 0; j < count; j++)  
  90.                                 {  
  91.                                     finalResults[0].Merge(finalResults[j]);  
  92.                                     finalResults[0].Columns["Name"].SetOrdinal(0);  
  93.                                 }  
  94.                             }  
  95.                         }  
  96.                     }  
  97.                     if (!finalResults[0].Columns.Contains("Status"))  
  98.                     {  
  99.                         finalResults[0].Columns.Add(new DataColumn("Status"typeof(String)));  
  100.                     }  
  101.                     if (!finalResults[0].Columns.Contains("DetailUri"))  
  102.                     {  
  103.                         finalResults[0].Columns.Add(new DataColumn("DetailUri"typeof(String)));  
  104.                     }  
  105.                     if (!finalResults[0].Columns.Contains("Score"))  
  106.                     {  
  107.                         finalResults[0].Columns.Add(new DataColumn("Score"typeof(Double)));  
  108.                     }  
  109.                     if (finalResults[0].Columns.Contains("Type"))  
  110.                     {  
  111.                         if (!finalResults[0].Columns.Contains("Status"))  
  112.                         {  
  113.                             finalResults[0].Columns["Type"].ColumnName = "Status";  
  114.                         }  
  115.                     }  
  116.                     if (finalResults[0].Columns.Contains("EntityName"))  
  117.                     {  
  118.                         if (!finalResults[0].Columns.Contains("Name"))  
  119.                         {  
  120.                             finalResults[0].Columns["EntityName"].ColumnName = "Name";  
  121.                         }  
  122.                     }  
  123.                     foreach (DataRow row in finalResults[0].Rows) // Loop over the rows.  
  124.                     {  
  125.                         string name = row["Name"].ToString().ToLower();  
  126.   
  127.                         string keyword = et1.Text.ToString().ToLower();  
  128.                         double score = System.Math.Round((GOATechnologies.Tools.StringMatch.Match(name, keyword) * 100), 2);  
  129.                         row["Score"] = score;  
  130.                     }  
  131.                 }  
  132.   
  133.                 catch(Exception ex) {  
  134.                     string msg = ex.Message;  
  135.                 }  
  136.   
  137.                 dt = finalResults [0];  
  138.                 MylistViewAdapter adapter=new MylistViewAdapter(this,businesslist);
                   lv1.Adapter = adapter;
                    progress.Hide();

please advice..
Answers (3)