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>