2017-08-17 47 views
-2
new Thread(() => 
    { 
     while (true) 
     {     
      IList<ScanResult> scanwifinetworks = wifiManager.ScanResults; 
      foreach (Android.Net.Wifi.ScanResult wifinetwork in scanwifinetworks) 
      { 
       try 
       { 
        if (wifissid != (wifinetwork.Ssid)) 
        { 
         wifissid = wifinetwork.Ssid; 
         lstSource.Add(new Person() { wifi_Rssi = wifinetwork.Level, wifi_ssid = wifissid }); 
         Console.WriteLine(wifi_rssi); 

         var adapter = new CustomAdapter(this, lstSource); 
         lstData.Adapter = adapter; 
         Console.WriteLine(WiFiNetworks); 
        } 
       } 
       catch (Exception) 
       { 
        Console.WriteLine("EXscption"); 
       } 
       Thread.Sleep(2000); 
      } 
     } 
    }).Start(); 

如果我嘗試做ListView中的任何事情,我可以補充,但是當我嘗試在線程添加它崩潰(lstData.Adapter = adapter;)。在線程的ListView適配器崩潰xamarin

回答

1

在Android中禁止從脫機線程修改UI。你需要將它發佈到UI線程並在那裏設置適配器。