Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVsevolod Kaganovych
3,801 PointsCan't add a new item in Adroid Menu
I did everything, that was advised here https://teamtreehouse.com/forum/android-menu-action-bar. But it doesn't work. I still cannot add an item.
4 Answers
Matheus G Oliveira
9,682 PointsHey Vsevolod,
Did you add a new item to the menu option over your res folder?
try checking out this documents
http://developer.android.com/guide/topics/ui/menus.html
Hope it helps
Harry James
14,780 PointsIt seems that this is a new issue coming out. I along with other users are having it too:
https://teamtreehouse.com/forum/not-able-to-get-the-share-action-icon-in-the-action-bar
Harry James
14,780 PointsHello again, if you check the link I provided earlier (https://teamtreehouse.com/forum/not-able-to-get-the-share-action-icon-in-the-action-bar), I have provided a fix there.
Hope it helps! :)
Vsevolod Kaganovych
3,801 PointsNope, it didn't help too. But thanks for your trying :)
Harry James
14,780 PointsOk. I'll still try and help you out. Can you make sure that your blog_web_view.xml file looks exactly like the code here?
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_action_share"
android:showAsAction="always"
android:title="@string/action_share">
</item>
</menu>
And that the 3 methods in BlogWebViewActivity look like this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_blog_web_view, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int itemId = item.getItemId();
if (itemId == R.id.action_share) {
sharePost();
}
return super.onOptionsItemSelected(item);
}
private void sharePost() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));
}
Or, you can post your blog_web_view.xml and BlogWebViewActivity.java on here using a site like www.pastebin.com and I'll take a look and see if anything jumps out.
Vsevolod Kaganovych
3,801 PointsThis is BlogWebViewActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.blog_web_view, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.action_share) {
sharePost();
}
return super.onOptionsItemSelected(item);
}
private void sharePost() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mUrl);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_chooser_title)));
}
And this is blog_web_view.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_share"
android:icon="@drawable/ic_action_share"
android:showAsAction="always"
android:title="@string/action_share">
</item>
</menu>
Sorry, didnt reply to you, little mistake.
Harry James
14,780 PointsI don't see anything wrong with this code and no problem about the reply. I do it to sometimes :)
What emulator are you running on that is not allowing you to see the action bar? It will only be displayed on Android 3.0 (API 11) or above. If you have tried on Android 3.0 or above, I'd be happy to take a look at your Project Files (You can export them by right clicking on your project >> Export >> General >> File System and then share them using Dropbox or a similar service). Then, I'd be able to test it from my side and see if I get your problem as well.
Harry James
14,780 PointsI'm going to be heading off for today now so I'll be able to help out tomorrow if you don't get your problem fixed. There'll probably be a few other forum members on right now in a different timezone who may be able to help out too so, hopefully someone may be able to fix the problem whilst I'm gone.
Best of luck!
Vsevolod Kaganovych
3,801 PointsThanks for you patience and help, It actually works today morning, don't know what happened. Answering your question, i'm using a Genymotion from the beggining.
Harry James
14,780 PointsHaha. Glad to hear it's fixed. Eclipse must've just have been buggy.