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 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.

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

download filesDownload the files.

ActionBarCompat with Share ShareActionProvider

Visit: ActionBarCompat Step-by-step

No comments: