I've been playing with Honeycomb for the last week and had a hard time to find something about more than one drop-down list in Action Bar. I've used this tutorial and successfully added one drop-down list to it. But I don't know how to add another one. Please tell me if you know how to do it. Thanks.
P.S. also one little this how can I change the position of elements in Action Bar(this is off topic)?
Not sure about Honeycomb but I was able to add two drop down lists to my action bar in JellyBean without using a custom view.
res/menu/main_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_main_spinner"
android:actionViewClass="android.widget.Spinner"
android:showAsAction="always"/>
<item
android:id="@+id/menu_status_spinner"
android:actionViewClass="android.widget.Spinner"
android:showAsAction="always"/>
</menu>
MyActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate( R.menu.main_menu, menu );
MenuItem mainMenuSpinner = menu.findItem( R.id.menu_main_spinner);
setupMainMenuSpinner( mainMenuSpinner );
MenuItem statusSpinner = menu.findItem( R.id.menu_status_spinner );
setupStatusSpinner( statusSpinner );
return super.onCreateOptionsMenu(menu);
}
private void setupMainMenuSpinner(MenuItem item) {
View view = item.getActionView();
if (view instanceof Spinner) {
Spinner spinner = (Spinner) view;
spinner.setAdapter(ArrayAdapter.createFromResource(this,
R.array.main_menu_options,
android.R.layout.simple_spinner_dropdown_item));
}
}
private void setupStatusSpinner(MenuItem item) {
View view = item.getActionView();
if (view instanceof Spinner) {
Spinner spinner = (Spinner) view;
spinner.setAdapter(ArrayAdapter.createFromResource(this,
R.array.status,
android.R.layout.simple_spinner_dropdown_item));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With