[Mono-dev] Update a data on a list

LaureneF lfaurevidal at algoria.fr
Thu Feb 14 17:52:50 UTC 2013


In my application, I display a list of contacts with their name, picture, and
presence status. 
The application receives an event everytime a contact changes his presence,
and what I am trying to do is to update the list with the contact's new
presence.

This is how I bind my list to a custom list adapter:

 ListView listView;
 listView = FindViewById<ListView>(Resource.Id.List);
 listView.Adapter = new ContactListAdapter(this, names);
           
And this is a part of the GetView of my ContactListAdapter
 public override View GetView(int position, View convertView, ViewGroup
parent)
        {
            var item = this.contacts.ElementAt(position);
            var view = convertView; // re-use an existing view, if one is
available
           // if (view == null || !(convertView is LinearLayout)) //
otherwise create a new one
                view =
context.LayoutInflater.Inflate(Resource.Layout.contactItemView, parent,
false);
            var p = context;
            var imageItem = view.FindViewById(Resource.Id.presence) as
ImageView;
           
          string status = null;
            foreach (CPresenceInfo pres in item.Presences)
            {
                if (pres.Type.ToString().Equals("TWS")) status =
pres.StatusBusy;
            }
            if (status != null)
            {
                if (status.Equals("ONLINE"))
imageItem.SetImageResource(Resource.Drawable.online);
                if (status.Equals("BUSY"))
imageItem.SetImageResource(Resource.Drawable.busy);
                if (status.Equals("ABSENT"))
imageItem.SetImageResource(Resource.Drawable.absent);
                if (status.Equals("OFFLINE"))
imageItem.SetImageResource(Resource.Drawable.offline);

            }
            return status;

            return view;
        }

And the method that receives the event:
        void CEventParser_OnPresenceChangedEvent(string personGuid,
CPresenceInfo presence)
        {
                //Update the contact row or the entire list??
        }

I don't know if I can update just one row in the list, or if I have to
update the entire list. But in both cases I don't know how to do...
I know there is a NotifyDataSetChanged() method but I don't know how and
where to use it.



--
View this message in context: http://mono.1490590.n4.nabble.com/Update-a-data-on-a-list-tp4658592.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list