I am getting an error error: Only the original thread that created a view hierarchy can touch its views
in line
BookingAdapter expListAd
Here is a cross platform solution in xamarin for this issue;
Device.BeginInvokeOnMainThread(() =>
{
//Your code here
});
You're calling GetServicesForUserCompleted
method from SalonServicesClient
on worker thread. Invoke it on the UI thread instead.
The linked article in the accepted answer talks about InvokeOnMainThread
which is an IOS thing. No idea why it was accepted as an answer for Android as the question is tagged.
For Android you use Activity.RunOnUiThread
. Relevant documentation is here: http://developer.xamarin.com/guides/android/advanced_topics/writing_responsive_applications/
Because you are rigging this up from somewhere that inherits from Activity
you can just wrap the relevant code so this:
BookingAdapter expListAdapter = new BookingAdapter (this, listDataHeader, listDataChild);
try{
explistView.SetAdapter (expListAdapter);
explistView.SetGroupIndicator (null);
}
catch(Exception e) {
Toast.MakeText (this,e+"",ToastLength.Long).Show();
}
becomes:
RunOnUiThread(() =>
{
BookingAdapter expListAdapter = new BookingAdapter (this, listDataHeader, listDataChild);
try{
explistView.SetAdapter (expListAdapter);
explistView.SetGroupIndicator (null);
}
catch(Exception e) {
Toast.MakeText (this,e+"",ToastLength.Long).Show();
}
});
That's really all there is to it.