Monday, December 16, 2013

Handle onOptionsItemSelected() for ActionBarCompat

This example override onOptionsItemSelected() method to handle user click on Options Menu in ActionBarCompat.

user click on Options Menu in ActionBarCompat
user click on Options Menu in ActionBarCompat
Modify MainActivity.java in last exercise "Add MenuItem to ActionBarCompat using Java", override onOptionsItemSelected(). Get the id of the clicked menu item by calling item.getItemId(), then compare with the id(s) defined.

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // TODO Auto-generated method stub
  //return super.onOptionsItemSelected(item);
  switch (item.getItemId()) {
        case R.id.action_settings: 
         //match with /res/menu/main.xml
            Toast.makeText(this, "Setting", Toast.LENGTH_SHORT).show();
            return true;
        case R.id.menuid_info:  
         //match with defined in onCreateOptionsMenu()
         Toast.makeText(this, "Info", Toast.LENGTH_SHORT).show();
            return true;
        default:
            return super.onOptionsItemSelected(item);    
  }
 }




download filesDownload the files.

Next:
ActionBarCompat with Share ShareActionProvider



Visit: ActionBarCompat Step-by-step

Description: Handle onOptionsItemSelected() for ActionBarCompat Rating: 4.5 Reviewer: Ringga - ItemReviewed: Handle onOptionsItemSelected() for ActionBarCompat

Ringga

Look for the best that you can get, even if it means you have to look for it from the worst.

If the violation of your copyright, please inform, we will remove Please allow 1-2 business days for an email response.

0 comments:

Post a Comment

 

Copyright @ 2013 Android Apps Download | History and Trivia - All Rights Reserved.