Menu inflater worked in v3.5.1 but not for me in v4.0 beta 5

745 views
Skip to first unread message

qbit

unread,
Jan 15, 2012, 9:35:05 PM1/15/12
to ActionBarSherlock
Hi guys,
How do inflate a menu with 4.0 beta 5?

3.5.1 - working:
...
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbar_list_items, menu);
return super.onCreateOptionsMenu(menu);
}


4.0 beta 5 - not working :
...
import android.view.MenuInflater;
...
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
...
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbar_list_items, menu);
return super.onCreateOptionsMenu(menu);
}

with a quick fix box saying:
The method inflate(int, Menu) in the type MenuInflater is not
applicable for the arguments (int, Menu)

I have read Jake saying stay away from the .internal. tree and I have
noticed that the sample code builds menus using the .add method.

Would someone please someone post an example of their abs imports and
their onCreateOptionsMenu method for 4.0.

Jake Wharton

unread,
Jan 15, 2012, 11:09:03 PM1/15/12
to actionba...@googlegroups.com
You have to use getSupportMenuInflater() now since the menus no longer inherit from the android.view.Menu* interfaces. I think I forgot to mention that in the blog post...

---
Jake Wharton
http://about.me/jakewharton

qbit

unread,
Jan 15, 2012, 11:24:21 PM1/15/12
to ActionBarSherlock
Thanks. Worked perfectly.

On Jan 16, 3:09 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> You have to use getSupportMenuInflater() now since the menus no longer
> inherit from the android.view.Menu* interfaces. I think I forgot to mention
> that in the blog post...
>
> ---
> Jake Whartonhttp://about.me/jakewharton

Thorsten Berlin

unread,
Feb 11, 2012, 3:47:12 AM2/11/12
to actionba...@googlegroups.com
How can I use getSupportMenuInflater() with a FragmentActivity in 4.0 beta 6? I included the ABS as project and the ASB support lib as JAR, but the mentioned method is not available in the FragmentActivity and the SherlockActivity not inherits from FragmentActivity. Are there any samples using ASB and fragments together (4.x trunk)?

Jake Wharton

unread,
Feb 11, 2012, 1:20:47 PM2/11/12
to actionba...@googlegroups.com
There aren't any fragment-based samples (yet) but I just confirmed that getSupportMenuInflater was included in the 4.0b6 support-lib jar. Make sure you're not also including the support jar from Google as well.

I've attached a version that I just built (based on the latest from the 4.0-wip branch).
actionbarsherlock-plugin-support-lib-4.0.0-SNAPSHOT.jar
Reply all
Reply to author
Forward
0 new messages