0

I am using an external API for some actions. One of the method takes a list of menu(xml) items like:

----.shape(R.menu.list).---

And here is my R.menu.list file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/share"
        android:title="Share"
        android:icon="@drawable/ic_share_grey600_18dp"/>

    <item android:id="@+id/upload"
        android:title="Upload"
        android:icon="@drawable/ic_notifications_green"/>
</menu>

The problem is that the items in this R.menu.list file are not known. They can vary. Say I have a button, on clicking it, I may have 3 items that are needed to be passed to .shape() method, and sometimes I may have 1 or so items. How can I achieve this.

1

1 Answer 1

0

Prepare different files i.e. R.menu.listShare, R.menu.list.Upload etc

While clicking buttons

i.e. Share -> call API with R.menu.listShare and

Upload -> call API with R.menu.Upload xml files

This way dynamically you can inflate menu from different menu files

This approach will be simple to implement and organize actions according to different buttons

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.