0

I've a screen with a button that is placed somewhere on the screen (near the top).

I would like to click on the button and get this result: A menu is opened right below the button and lets you choose text(from the list) or write my own text(where "type here.." is written).

enter image description here

I've this popup menu:

PopupMenu popupMenu = new PopupMenu(this, buttonChooseText);
    for (int i = 0; i < listDefaultText.size(); ++i) {
        // the list is from String type and contains "text1" and so on
        popupMenu.getMenu().add(listDefaultText.get(i);
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getTitle().toString()) {
                case "Text1" :
                    //execute "text1" action
                    break;
                case "Text2" :
                    //execute "text2" action
                    break;
            }
            return false;
        }
    });
    popupMenu.show();

So how can I get this result?

Maor Cohen
  • 936
  • 2
  • 18
  • 33
  • Why do you want to enter text, for search or adding item – codecrazer Jul 19 '17 at 08:09
  • if the user don't want any of the list (text1, text2...), he can write his own text. So if he presses on "Submit", I take this edittext string and display it somewhere else on the screen (not on the popup). and if he choose from the list, I take the text of the pressed item ("text1" and so on..) and display it somewhere.. Hope you got it – Maor Cohen Jul 19 '17 at 08:30

1 Answers1

1

PopupMenu will likely fall short to meet your requirement since it doesn't offer much of flexibility in terms of comprising views other than menu item. Use PopupWindow instead as it supports custom layout. Here is an example of it.

fluffyBatman
  • 6,524
  • 3
  • 24
  • 25