我應該使用自定義線創建自定義彈出式菜單,這就是爲什麼我使用自定義對象創建了數組列表,因爲每行必須包含標題和副標題。當我必須把這些物品,在彈出的我得到這個錯誤:自定義數組列表彈出式菜單
The type of the expression must be an array type but it resolved to
ArrayList<PopupItem>
我的代碼:
navMenuOverflowTitles =new String[]{"Text","Dashboard","Settings", "Order","Filter"};
navMenuOverflowSubTitles = new String[]{"standard","Recently", "","",""};
mPopupList = new ArrayList<PopupItem>();
mPopupList.add(new PopupItem(1,navMenuOverflowTitles[0], navMenuOverflowSubTitles[0], "item1"));
mPopupList.add(new PopupItem(2,navMenuOverflowTitles[1], navMenuOverflowSubTitles[1], "item2"));
mPopupList.add(new PopupItem(3,navMenuOverflowTitles[2], navMenuOverflowSubTitles[2], "item3"));
mPopupList.add(new PopupItem(4,navMenuOverflowTitles[3], navMenuOverflowSubTitles[3], "item4"));
mPopupList.add(new PopupItem(5,navMenuOverflowTitles[4], navMenuOverflowSubTitles[4], "item5"));
View menuItemView = findViewById(R.id.menu_overflow);
popupMenu = new PopupMenu(this, menuItemView);
popupMenu.getMenu().add(Menu.NONE, 1, Menu.NONE, mPopupList[0]);//the error is here
在PopupItem.java
public class PopupItem
{
private int itemId;
private String subtitleText;
private String titleText;
private String tag;
public PopupItem(int itemId, String title, String subtitle, String tag) {
this.itemId=itemId;
this.subtitleText=subtitle;
this.titleText=title;
this.tag = tag;
}
}
我得到這樣的錯誤**類型菜單中Add方法(INT,INT,INT,爲CharSequence)不適用於參數(int,int,int, PopupItem)** –
最後一個參數需要是一個CharSequence,所以你的項目的文本表示(你想在菜單中看到的文本)。有一個多行菜單項是不是真的可能 –
我添加一個方法getString()在PopupItem.java爲concate title和subtitle。我的解決方案是 –