Monday, June 10, 2013

[android help] Monodroid ListView update problems


Monodroid ListView update problems



I'm not sure how much this will help anyone, but it seems to work fine in my instance.


I have a ViewModel class that keeps all the data I update within the App and trigger a "Collection Updated" action when a collection changes.



// All within ViewModel.cs

private Action SearchResultsUpdated;

private List m_oSearchResults;

Public List SearchResults
{
get
{
if (m_oSearchResults == null)
m_oSearchResults = new List ();
return m_oSearchResults;
}
set
{
if (value != m_oSearchResults)
{
m_oSearchResults = value;
//
// Fire update event
if (SearchResultsUpdated != null)
SearchResultsUpdated ();
}
}
}


I then add a handler for this event within the adapter class.



// All within SearchResultsAdapter.cs

public class SearchResultsAdapter : BaseAdapter
{
.
.
// Constructor
public SearchResultsAdapter (Activity oContext)
: base ()
{
// Add handler for list refresh
ViewModel.SearchResultsUpdated += NotifyDataSetChanged;
//
m_oContext = oContext;
}
}


Within the adapter I use the collection ViewModel.SearchResults as the data context for the list view. Hope that helps and is thorough enough for everyone to understand.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...