Coder Social home page Coder Social logo

Menu Item Edit about bottomsheetmenu HOT 9 CLOSED

kennyc1012 avatar kennyc1012 commented on July 29, 2024
Menu Item Edit

from bottomsheetmenu.

Comments (9)

Kennyc1012 avatar Kennyc1012 commented on July 29, 2024

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();

from bottomsheetmenu.

fcannizzaro avatar fcannizzaro commented on July 29, 2024

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

from bottomsheetmenu.

allanguintu avatar allanguintu commented on July 29, 2024

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

from bottomsheetmenu.

krhckd93 avatar krhckd93 commented on July 29, 2024

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.

Kennyc1012 avatar Kennyc1012 commented on July 29, 2024

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.

krhckd93 avatar krhckd93 commented on July 29, 2024

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

from bottomsheetmenu.

krhckd93 avatar krhckd93 commented on July 29, 2024

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.

Kennyc1012 avatar Kennyc1012 commented on July 29, 2024

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.

krhckd93 avatar krhckd93 commented on July 29, 2024

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

from bottomsheetmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.