Example #1
0
        public override void bindView(android.view.View view, android.content.Context context
                                      , android.database.Cursor cursor)
        {
            android.widget.SimpleCursorAdapter.ViewBinder binder = mViewBinder;
            int count = mTo.Length;

            int[] from = mFrom;
            int[] to   = mTo;
            {
                for (int i = 0; i < count; i++)
                {
                    android.view.View v = view.findViewById(to[i]);
                    if (v != null)
                    {
                        bool bound = false;
                        if (binder != null)
                        {
                            bound = binder.setViewValue(v, cursor, from[i]);
                        }
                        if (!bound)
                        {
                            string text = cursor.getString(from[i]);
                            if (text == null)
                            {
                                text = string.Empty;
                            }
                            if (v is android.widget.TextView)
                            {
                                setViewText((android.widget.TextView)v, text);
                            }
                            else
                            {
                                if (v is android.widget.ImageView)
                                {
                                    setViewImage((android.widget.ImageView)v, text);
                                }
                                else
                                {
                                    throw new System.InvalidOperationException(v.GetType().FullName + " is not a " +
                                                                               " view that can be bounds by this SimpleCursorAdapter");
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private void bindView(int position, android.view.View view)
 {
     java.util.Map <string, object> dataSet = mData.get(position);
     if (dataSet == null)
     {
         return;
     }
     android.widget.SimpleAdapter.ViewBinder binder = mViewBinder;
     string[] from  = mFrom;
     int[]    to    = mTo;
     int      count = to.Length;
     {
         for (int i = 0; i < count; i++)
         {
             android.view.View v = view.findViewById(to[i]);
             if (v != null)
             {
                 object data = dataSet.get(from[i]);
                 string text = data == null ? string.Empty : data.ToString();
                 if (text == null)
                 {
                     text = string.Empty;
                 }
                 bool bound = false;
                 if (binder != null)
                 {
                     bound = binder.setViewValue(v, data, text);
                 }
                 if (!bound)
                 {
                     if (v is android.widget.Checkable)
                     {
                         if (data is bool)
                         {
                             ((android.widget.Checkable)v).setChecked((bool)data);
                         }
                         else
                         {
                             if (v is android.widget.TextView)
                             {
                                 // Note: keep the instanceof TextView check at the bottom of these
                                 // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                                 setViewText((android.widget.TextView)v, text);
                             }
                             else
                             {
                                 throw new System.InvalidOperationException(v.GetType().FullName + " should be bound to a Boolean, not a "
                                                                            + (data == null ? "<unknown type>" : data.GetType().ToString()));
                             }
                         }
                     }
                     else
                     {
                         if (v is android.widget.TextView)
                         {
                             // Note: keep the instanceof TextView check at the bottom of these
                             // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                             setViewText((android.widget.TextView)v, text);
                         }
                         else
                         {
                             if (v is android.widget.ImageView)
                             {
                                 if (data is int)
                                 {
                                     setViewImage((android.widget.ImageView)v, (int)data);
                                 }
                                 else
                                 {
                                     setViewImage((android.widget.ImageView)v, text);
                                 }
                             }
                             else
                             {
                                 throw new System.InvalidOperationException(v.GetType().FullName + " is not a " +
                                                                            " view that can be bounds by this SimpleAdapter");
                             }
                         }
                     }
                 }
             }
         }
     }
 }