Material-BottomNavigation icon indicating copy to clipboard operation
Material-BottomNavigation copied to clipboard

How to implement onitemclick listener?

Open mugabi0978 opened this issue 8 years ago • 3 comments

How can I set my own fragment to be listened to when a specific item on the navigation bar is clicked? I would appreciate help from any person.

Thanks very much.

mugabi0978 avatar May 21 '17 18:05 mugabi0978

Hello mugabi,

BottomNavigation bottomNavigation = (BottomNavigation) view.findViewById(R.id.bottom_navigation);
bottomNavigation.setOnMenuItemClickListener(new BottomNavigation.OnMenuItemSelectionListener() {
            @Override
            public void onMenuItemSelect(@IdRes int i, int i1, boolean b) {
                // Do something, the variable i1 is the item's position clicked
            }

            @Override
            public void onMenuItemReselect(@IdRes int i, int i1, boolean b) {
                // Do something
            }
        });

I hope this clarify you.

cbaez440 avatar May 21 '17 22:05 cbaez440

Hello ;

Fragment selectedfragment = null;
                selectedfragment = BlankFragment.newInstance();
                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                //fragmentTransaction.replace(R.id.ViewPager01, blankFragment);

                fragmentTransaction.replace(R.id.ViewPager01, selectedfragment);
                fragmentTransaction.commit();

I tried the code above but the fragment doesnt display anything:- Could you please direct me on how to display it correctly;-

Thanks.

mugabi0978 avatar May 22 '17 13:05 mugabi0978

Hello mugabi,

BottomNavigation bottomNavigation = (BottomNavigation) view.findViewById(R.id.bottom_navigation);
bottomNavigation.setOnMenuItemClickListener(new BottomNavigation.OnMenuItemSelectionListener() {
            @Override
            public void onMenuItemSelect(@IdRes int i, int i1, boolean b) {
                // Do something, the variable i1 is the item's position clicked
            }

            @Override
            public void onMenuItemReselect(@IdRes int i, int i1, boolean b) {
                // Do something
            }
        });

I hope this clarify you.

I think it would be better for everyone using your library to document it , especially on how to use the MenuItemSelect method

theshid avatar Jan 24 '19 15:01 theshid