Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu Item Edit #9

Closed
fcannizzaro opened this issue Sep 30, 2015 · 9 comments
Closed

Menu Item Edit #9

fcannizzaro opened this issue Sep 30, 2015 · 9 comments

Comments

@fcannizzaro
Copy link

Hi! Your library is great 👍
but I can't understand how to access to Menu Items for change visibility/title/icon of each item using static menu resource as sheet.

How can I do that? ( before the sheet is visible )
Thanks 😄

@Kennyc1012
Copy link
Owner

This has a few solutions.

  1. Have multiple menu files based on your scenarios (easiest)
  2. Inflate a menu object (using BottomSheetMenu) and take the appropriate actions. An example could be
Context context...
Menu menu = new BottomSheetMenu(context);
// This will inflate the menu and populate it
new MenuInflater(context).inflate(R.menu.my_menu,menu);
// Now you have a menu object with access to the Menuitems
Menuitem item = menu.findItem(R.id.some_id);
// Call whatever method you need on the MenuItem
item.setIcon(R.drawable.some_icon);
item.setVisibile(isVisible);
// Once you have configured your MenuItems accordingly, you can create the BottomSheet
new BottomSheet.Builder(context)
.setMenu(menu)
...
.show();

@fcannizzaro
Copy link
Author

Great! Yeah the first is the best. I cannot understand how I didn't think that before 😆

@allanguintu
Copy link

Hi,
I cant seem to disable menuitem. Is there any way to disable menuitems?

@Kennyc1012 Kennyc1012 mentioned this issue Mar 13, 2018
@krhckd93
Copy link

Hi, thanks for the nice library. I am trying to hide menu items based on where it is called from, and I followed this approach. However, when I try to find the item with "menu.findItem(R.id.invite)", it is throwing 'Method threw 'java.lang.ArrayIndexOutOfBoundsException' exception.'. Since other users have not reported this, there's probably something wrong with the way I am using it. Can you please tell me where am I doing it wrong? I have added a sample code below with the menu I am inflating. Thank you!

<?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/item_invite"
        android:title="@string/action_invite"
        app:showAsAction="always" />
    <item
        android:id="@+id/item_schedule"
        android:title="@string/action_schedule"
        app:showAsAction="always" />
    <item
        android:id="@+id/item_remind"
        android:title="@string/action_remind"
        app:showAsAction="always" />
    <item
        android:id="@+id/item_assign"
        android:title="@string/action_assign"
        app:showAsAction="always" />
    <item
        android:id="@+id/action_change_status"
        android:title="@string/action_change_status"
        app:showAsAction="always" />
val menu = BottomSheetMenu(context)
MenuInflater(context).inflate(R.menu.menu_actions, menu)
menu.findItem(R.id.item_invite)

@Kennyc1012
Copy link
Owner

The more I think about it, disabling items from the menu won't work since the adapter just ignores those properties anyways, you would have to remove it from the list of menu items when you pass it to the adapter. I would recommend using different menu files for now as that is the easiest solution.

As for why the menu is throwing an error, I'm not sure. Can you provide a full stack trace?

@krhckd93
Copy link

Thanks for the quick response. Let me get back with the required details.

@krhckd93
Copy link

The menu item ids I am passing and the ids it looks for is not same I think. I have added the relevant details below.
Menu Item Ids :

R.id.item_invite - 1000324
R.id.item_schedule_live_session - -1000292
R.id.item_remind_candidate - -1000866
R.id.item_assign_panel - -1000291
R.id.item_extend_last_date - -1001080
R.id.action_change_status - -1000325

Menu Items :

{
    "mItems" : [{
	"mTitle" : "Invite",
	"mId" : 2131296711
}, {
	"mTitle" : "Schedule",
	"mId" : 2131296719
}, {
	"mTitle" : "Remind",
	"mId" : 2131296715
}, {
	"mTitle" : "Assign",
	"mId" : 2131296703
}, {
	"mTitle" : "Change Status",
	"mId" : 2131296272
}] 
}

Stack trace :

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.talview.recruit, PID: 12493
java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
    at java.util.ArrayList.get(ArrayList.java:439)
    at com.kennyc.bottomsheet.menu.BottomSheetMenu.findItem(BottomSheetMenu.java:137)
    at com.recview.talruit.app.ac.listfragment.ACListFragment.createListActions(ACListFragment.kt:243)
    at com.recview.talruit.app.ac.listfragment.ACListFragment.onCreateView(ACListFragment.kt:107)
    at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
    at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
    at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
    at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:168)
    at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
    at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
    at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
    at android.view.View.measure(View.java:23355)
    at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
    at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6758)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
    at android.view.View.measure(View.java:23355)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2917)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1747)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2040)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1635)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7795)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1172)
    at android.view.Choreographer.doCallbacks(Choreographer.java:984)
    at android.view.Choreographer.doFrame(Choreographer.java:809)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1158)
    at android.os.Handler.handleCallback(Handler.java:873)

@Kennyc1012
Copy link
Owner

It's possible the ids are being changed in within the library. I think what you can do is loop through the menu items and compare on the title (not ideal). I'll have to look into why the ids are mis-matching.

@krhckd93
Copy link

ok, thanks. I'll check it out. Btw mItems is private in BottomSheetMenu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants