2011-10-24 38 views
0

我想添加一個ListView到選項菜單中,所以點擊它時會彈出並允許用戶滾動瀏覽並與其他列表視圖進行交互。Android將列表視圖添加到選項菜單

使用這個東西對XML:

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
     <ListView android:id="@+id/menuGroupsList" android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/> 
</menu> 

這對於代碼:

public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.layout.menu, menu); 
    ListView list = (ListView)findViewById(R.id.menuGroupsList); 
} 

返回從findViewById空。

這是可能的嗎?

謝謝

+0

我非常有信心,這是不可能的。 – goto10

+0

是您真正需要的選項菜單嗎?或者你是指上下文菜單?我很難想象如何使用列表視圖來顯示選項菜單。 – Maggie

+0

@Maggie我想要實現的是一個彈出列表視圖,但是當點擊android上的設置按鈕時彈出窗口。 – Gal

回答

1

請勿使用MenuInflater。相反,創建一個帶有列表的自定義佈局。
覆蓋onPrepareOptionsMenu(..)並創建一個對話框,用您的自定義佈局膨脹。

Dialog dlg = new Dialog(context); 
dlg.setContentView(R.layout.splashscreen); 
dlg.show(); 
相關問題