last day (14 days later) » 

9:24 AM
-1
A: Populating and updating a ListView in Xamarin

GiorgiYou need to add the item to the ArrayAdapter itself: ListAdapter.Add("The server is running at port localEndPoint..."); ListAdapter.NotifyDataSetChanged(); If your code runs on background thread you will need to wrap it in RunOnUiThread as you have mentioned in your question.

 
This does not work! Still nothing..
 
@Canox: Does the code in Server run on background thead?
 
Like above it's going through a delegate. I'm calling TcpListener myList = new TcpListener(ipAddress, 8001); and myList.Start(); - Could this be blocking the ListView?
 
@Canox: Can you try updating listview before starting the listener?
 
I put it in an own method. It works now. When I put it before starting the listener it does not work. How can this be avoided?
 
9:24 AM
@Canox: Post the full code of Server method in your question.
 
Done! Updated it.
 
I guess the listview isn't updating because of the blocking calls in the Server method
You should move the code for accepting connections to a background thread
 
Hi! :)
Ok I try it.
But one question: I'm invoking it with
ListAdapter.Add("The server is running at port localEndPoint...");
RunOnUiThread(() =>
{
ListAdapter.NotifyDataSetChanged();
});
I thought that is enough
 
no that's not enough because Socket s = myList.AcceptSocket();
blocks the methods
and the ui thread cannot update the screen
 
How would the code look like?
 
9:32 AM
You need to move that code to another thread
 
Ok I try it
Ok now I did this:
Thread thread = new Thread(new ThreadStart(ServerSide));
button.Click += delegate { thread.Start(); };
It crashes when trying to add something to the adapter. Now I have to invoke it right? But I don't know how to do this in Xamarin. MethodInvoker does not work
 
RunOnUiThread(() =>
{
ListAdapter.Add("The server is running at port localEndPoint...");
ListAdapter.NotifyDataSetChanged();
});
 
It works!
Thank you so much! :)
 
Great
 
I voze up and accept your answer
So, have a nice day and thanks again!
 
9:43 AM
thanks
 

last day (14 days later) »