Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:27:20+00:00 2026-06-09T15:27:20+00:00

I’ve come across a problem that I have searched and searched for a solution

  • 0

I’ve come across a problem that I have searched and searched for a solution for, and cannot find one. I am trying to set up a Preference screen which is opened by an action button on an ActionBarSherlock action bar. The buttons appear on the action bar, but they don’t do anything when pressed. They are supposed to start a new intent, but it doesn’t. Here’s some code:

Main.java:

package com.myname.minteract;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;

import android.content.Intent;
import android.os.Bundle;

public class Main extends SherlockFragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.activity_main, menu);
        menu.add("Add Server")
        .setIcon(R.drawable.ic_action_add_server)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        menu.add("Refresh Servers")
        .setIcon(R.drawable.ic_action_refresh)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        menu.add("Settings")
        .setIcon(R.drawable.ic_action_options)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        return(super.onCreateOptionsMenu(menu));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.addServer:
            startActivity(new Intent(this, AddServer.class));
            return(true);
        case R.id.settings:
            startActivity(new Intent(this, Settings.class));
            return(true);
        }
        return(super.onOptionsItemSelected(item));
    }
}

My other class files and xml files are identical to the ones found here, with minor name changes (posting all of my code would take up an awful lot of space).

Hopefully this is enough information. I am fairly new to Android and very new to ActionBarSherlock, so I may be missing something fairly easy. I’ve tried using logcat and such, but the button literally does nothing, it doesn’t even show up on the logcat with an error.

Thanks!

Extra note: I am testing my app using a HTC Sensation 4G running ICS and a MyTouch 3G running Froyo (to make sure it is compatible with pre-honeycomb devices).

EDIT:

Here’s my /res/menu/activity_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_settings"
        android:title="@string/menu_settings"
        android:orderInCategory="100"
        android:showAsAction="never" />
    <item android:id="@+id/addServer"
        android:icon="@drawable/ic_action_add_server"
        android:title="Add Server" />
    <item android:id="@+id/refreshServers"
        android:icon="@drawable/ic_action_refresh"
        android:title= "Refresh Servers" />
    <item android:id="@+id/settings"
        android:icon="@drawable/ic_action_options"
        android:title="Settings" />
</menu>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:27:21+00:00Added an answer on June 9, 2026 at 3:27 pm

    You’ve set the ID of everything in the XML file, and set everything else up there as well, so there is no need to use menu.add(...) in your main code. Simply inflate the Menu and all will be well.

    Additionally, since you’ve handled the event, return true instead. Try this:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.activity_main, menu);
        return(true);
    }
    

    Personally I would recommend adding these as <item ...>s in res/menu/activity_main.xml instead of programmatically, but if this works for you, then that’s what matters, right?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.