I have a ListView and I am passing value to this list using ArrayAdapter.
This is what I did.
first I created string array:
private static readonly string[] menuItemNames = new string[] {
"Home", "New", "Delete", "Submit", "Help"
};
And then created ArrayAdapter:
this.MyMenuList.Adapter = new ArrayAdapter<string> (this, Resource.Layout.item_menu, Resource.Id.MenuItemText, menuItemNames);
And this seems to work fine. The values from menuItemNames array goes into the list and makes a new item. But next to each item, I have an icon. How Can I set the icon of each one?
This is what I tried:
Drawable sideIcon1 = context.Resources.GetDrawable (Resource.Drawable.home_icon);
Drawable sideIcon2 = context.Resources.GetDrawable (Resource.Drawable.new_icon);
Drawable sideIcon3 = context.Resources.GetDrawable (Resource.Drawable.delete_icon);
Drawable sideIcon4 = context.Resources.GetDrawable (Resource.Drawable.submit_icon);
Drawable sideIcon5 = context.Resources.GetDrawable (Resource.Drawable.help_icon);
Then, made drawable array:
Drawable[] sideMenuItemIconsDrawables = new Drawable[] {
sideIcon1, sideIcon2, sideIcon3, sideIcon4, sideIcon5
};
And then make a new ArrayAdapter:
this.MyMenuList.Adapter = new ArrayAdapter<Drawable> (this, Resource.Layout.item_menu, Resource.Id.ImgView, sideMenuItemIconsDrawables);
This doesn't seem to work.
What do I nee to pass instead of drawable to change the image of that ImageView ?
Thank you for your time.
// ===========================================================
EDIT: So this is what I tried. But it crashes my app before even the view loads. The adapter count changes but it just crashes after that.
IList<IDictionary<string, object>> menuItemNames = new List<IDictionary<string, object>> ();
Dictionary<string, object> sideItem1 = new Dictionary<string, object> ();
sideItem1.Add ("text", "SideMenuItem1");
sideItem1.Add ("icon", Resource.Drawable.menu_Icon);
Dictionary<string, object> sideItem2 = new Dictionary<string, object> ();
sideItem2.Add ("text", "SideMenuItem2");
sideItem2.Add ("icon", Resource.Drawable.back_arrow_box);
Dictionary<string, object> sideItem3 = new Dictionary<string, object> ();
sideItem3.Add ("text", "SideMenuItem3");
sideItem3.Add ("icon", Resource.Drawable.bar_addAbsence);
Dictionary<string, object> sideItem4 = new Dictionary<string, object> ();
sideItem4.Add ("text", "SideMenuItem4");
sideItem4.Add ("icon", Resource.Drawable.bar_addExpense);
Dictionary<string, object> sideItem5 = new Dictionary<string, object> ();
sideItem5.Add ("text", "SideMenuItem5");
sideItem5.Add ("icon", Resource.Drawable.bar_addTime);
menuItemNames.Add (sideItem1);
menuItemNames.Add (sideItem2);
menuItemNames.Add (sideItem3);
menuItemNames.Add (sideItem4);
menuItemNames.Add (sideItem5);
string[] sideMenuFromArr = { "text", "icon" };
int[] sideMenuToArr = { Resource.Id.textSideMenuItem, Resource.Id.imgViewSideMenuItemIcon };
SimpleAdapter sideMenuListAdapter = new SimpleAdapter (context, menuItemNames, Resource.Layout.item_menu, sideMenuFromArr, sideMenuToArr);
this.absHomeSideMenuList.Adapter = sideMenuListAdapter;