Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

android - Setting PopupMenu menu items programmatically

I have a PopupMenu and I know the usual way to associate a menu to it is to use popup.getMenuInflater().inflate(R.menu.my_menu, popup.getMenu()); or something of the like. My problem is, I have an array of items that I want in the menu and I need to be able to change them programmatically in Java. How can I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just figured it out; for anyone who runs into this same problem you just do:

popup.getMenu().add(groupId, itemId, order, title);

for each MenuItem you want to add.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...