Comments (9)
This has a few solutions.
- Have multiple menu files based on your scenarios (easiest)
- 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();
from bottomsheetmenu.
Great! Yeah the first is the best. I cannot understand how I didn't think that before 😆
from bottomsheetmenu.
Hi,
I cant seem to disable menuitem. Is there any way to disable menuitems?
from bottomsheetmenu.
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)
from bottomsheetmenu.
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?
from bottomsheetmenu.
Thanks for the quick response. Let me get back with the required details.
from bottomsheetmenu.
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)
from bottomsheetmenu.
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.
from bottomsheetmenu.
ok, thanks. I'll check it out. Btw mItems is private in BottomSheetMenu.
from bottomsheetmenu.
Related Issues (20)
- On Resume bottom sheet Hides and expands HOT 7
- Set click listener for customview buttons HOT 2
- Bottom sheet with lot of content will cover whole screen? HOT 2
- hey HOT 9
- Unable to set background for custom view HOT 2
- The exit animation often blocked when press the back button. HOT 2
- Open keyboard on custom layout with edittext HOT 1
- BottomSheet not anchoring to bottom of screen HOT 2
- Failed to resolve HOT 1
- There is a problem HOT 1
- how to show menu in State_Expanded when bottom sheet is shown in landscape mode? HOT 2
- Error when building project "bottom_sheet_list_item_color_dark not found HOT 1
- Impossible to change font size? HOT 1
- MinSdk 19 is required HOT 1
- Crash on rotation
- More than one file was found with OS independent path 'META-INF/library_release.kotlin_module'.
- Crash On Rotation
- QUERY_ALL_PACKAGES permission HOT 4
- Crash when app goes to background HOT 1
- Top padding remains visible after we define empty title HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bottomsheetmenu.