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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Aleena
  • 273
  • 4
  • 12

1 Answers1

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

Kushal
  • 8,100
  • 9
  • 63
  • 82