Android add listview to OptionsMenu

459 Views Asked by At

I want to add a ListView to the options menu so when clicked it will pop up and allow the user to scroll through it and interact it without the same as any other listview.

using something this for the 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>

and this for the code:

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

returns null from the findViewById.

Is this at all possible?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

Don't use MenuInflater. Instead, create a custom layout with a list in it.
Override onPrepareOptionsMenu(..) and create a Dialog which you inflate with your custom layout.

Dialog dlg = new Dialog(context);
dlg.setContentView(R.layout.splashscreen);
dlg.show();