1

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;
        }
    }
John Owuor
  • 63
  • 1
  • 6

1 Answers1

0

on SelectItem(), have you check if this is triggered at all?
In my cases clicks doesn't work when something else that is inside this view steam focus, for example if you make a custom ListView with a checkbox inside then the checkbox might steal the focus and alter the expected behavior.
You must then set focusable, focusableintouchmode and maybe clickable to false in this checkbox. Check if your problem is related to that.

CDrosos
  • 2,418
  • 4
  • 26
  • 49