JuiCe
JuiCe

Reputation: 4191

OptionsMenu onOptionsSelected gives me nothing

I am trying to make a simple Activity which has a menu with two buttons. The first button will load a separate activity, while the second button I am leaving with nothing to do for now. I have put log statements everywhere but the only one which is executed is the one in onCreateOptionsMenu.

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up window View
    setContentView(R.layout.main);

    Log.i( "onCreate", "veryBeginning" );
}

public boolean onCreateOptionsMenu( Menu menu ) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate( R.menu.option_menu, menu );
    Log.i( "onCreateOptionsMenu", "hereasd" );
    return true;
}

public boolean onOptionsSelected( MenuItem item ) {
    Log.i( "onOptionsSelected", "start" );
    switch( item.getItemId() ) {
    case R.id.connect:
        Log.i( "onOptionsSelected" , "r.id.connect" );
        startActivity( new Intent(getApplicationContext(), DeviceList.class ) );
        finish();
        return true;
    case R.id.preferences:
        Log.i( "onOptionsSelected" , "r.id.preferences" );
        return true;
    default:
        Log.i( "onOptionsSelected" , "r.id.?" );
        return super.onContextItemSelected( item );
    }
}

I start the program on my device, open the menu, and click both buttons numerous times, but none of the Logs are showing up in my LogCat.

This is my LogCat

06-13 14:11:34.643: I/onCreate(15262): veryBeginning
06-13 14:11:49.098: W/KeyCharacterMap(15080): No keyboard for id 0
06-13 14:11:49.098: W/KeyCharacterMap(15080): Using default keymap:/system/usr/keychars/qwerty.kcm.bin
06-13 14:11:49.098: I/onCreateOptionsMenu(15080): hereasd

Upvotes: 1

Views: 150

Answers (1)

Eight
Eight

Reputation: 4284

use onOptionsItemSelected(MenuItem item). see here.

Upvotes: 2

Related Questions