I have successfully created a custom side navigation menu with icons. I now want to detect item click events on the list so as to start new activities from the dashboard activity but the SelectItem method does not fire on item click.
This is my SideMenu method that creates the navigation drawer
private void SideMenu()
{
string[] appActions = new string[]{"Transactions", "Budgeting","Invoicing", "Bills", "\n", "Reminders", "\n", "Reports", "Accounts", "\n", "Logout" };
int[] icons = new int[]{Resource.Drawable.sidenavtransactions, Resource.Drawable.sidenavbudget, Resource.Drawable.sidenavinvoicing, Resource.Drawable.sidenavbills, Resource.Drawable.trans, Resource.Drawable.sidenavreminders, Resource.Drawable.trans, Resource.Drawable.trans, Resource.Drawable.trans, Resource.Drawable.trans, Resource.Drawable.trans };
actions = new List<Actions> ();
for (int i = 0; i < icons.Length; i++) {
Actions action = new Actions ();
action.actionName = appActions[i];
action.actionIcon = icons[i];
actions.Add (action);
}
drawer = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);
drawerList = FindViewById<ListView> (Resource.Id.left_drawer);
drawerList.Adapter = new NavigationDrawerAdapter (this, actions);
drawerList.ItemClick += (sender, e) => SelectItem(e.Position);
ActionBar.SetDisplayHomeAsUpEnabled (true);
ActionBar.SetHomeButtonEnabled (true);
drawerToggle = new MyActionBarDrawerToggle (this, drawer, Resource.Drawable.hamburger, Resource.String.DrawerOpen, Resource.String.DrawerClose);
drawerToggle.DrawerClosed += delegate {
ActionBar.Title = title;
InvalidateOptionsMenu ();
};
drawerToggle.DrawerOpened += delegate {
ActionBar.Title = drawerTitle;
drawerList.BringToFront();
drawer.RequestLayout();
InvalidateOptionsMenu();
};
drawer.SetDrawerListener (drawerToggle);
}
This is the SelectItem method that is supposed to be invoked on item click
private void SelectItem(int position)
{
switch (position) {
case 0:
Toast.MakeText (this, actions [0].actionName, ToastLength.Short).Show ();
break;
case 1:
Toast.MakeText (this, actions [1].actionName, ToastLength.Short).Show ();
break;
case 2:
Toast.MakeText (this, actions [2].actionName, ToastLength.Short).Show ();
break;
case 3:
Toast.MakeText (this, actions [3].actionName, ToastLength.Short).Show ();
break;
case 4:
Toast.MakeText (this, actions [4].actionName, ToastLength.Short).Show ();
break;
default:
break;
}
}