簡體   English   中英

彈出菜單-如何在LinearLayout中以編程方式進行設置

[英]Popup Menu -How to set programatically inside the LinearLayout

我想在LinearLayout中設置彈出菜單。

這是我的代碼。

for(int i=0;i<ev.size();i++)
                {
                    LinearLayout rl1 = new LinearLayout(getActivity());
                    rl1.setOrientation(LinearLayout.VERTICAL);
                    pum1 = new PopupMenu(getActivity(), view);
                    Event ebn=ev.get(i);
                    CalEvent cal = CalEvent.getCalEvent(ebn.getDescription());
                    pum.getMenu().add(Menu.NONE,ebn.getColor(),Menu.NONE,ebn.getTitle());
                    pum.getMenu().add(Menu.NONE,ebn.getColor(),Menu.NONE,cal.event_start);
                    rl1.addView(pum);
                }   

我遇到此錯誤-“ ViewGroup類型的方法addView(View)不適用於參數(PopupMenu)”。 請幫我

我認為您想在每個數據上打開彈出菜單。

在這種情況下,您必須創建自定義listview,在其中將創建適配器類,並且在該適配器類中,您可以在每個視圖上設置彈出菜單。

如果要創建像日歷這樣的布局,則應將GridLayout與自定義適配器一起使用,在其中使用set popupMenu。 這是示例: https : //stackoverflow.com/a/26545481/3864698

實際上,您可以使用: https : //github.com/roomorama/Caldroid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM