A
A
artem2021-03-21 20:23:12
Android
artem, 2021-03-21 20:23:12

How to refer to sub-item of menu menuItem?

How can I refer to the submenu menuItem?
I tried to assign menuItem id variable in onCreateOptionsMenu:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
       getMenuInflater().inflate(R.menu.menu, menu);
       menuItem = menu.getItem(0);                           // Первый способ
       menuItem = menu.getItem(R.id.addElement);   // Второй способ
       menuItem = menu.findItem(R.id.addElement);  // Третий способ
       
       return super.onCreateOptionsMenu(menu);
    }


I will need to refer to this variable in onCreate

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question