Example usage for android.app Fragment onOptionsItemSelected

List of usage examples for android.app Fragment onOptionsItemSelected

Introduction

In this page you can find the example usage for android.app Fragment onOptionsItemSelected.

Prototype

public boolean onOptionsItemSelected(MenuItem item) 

Source Link

Document

This hook is called whenever an item in your options menu is selected.

Usage

From source file:tw.idv.palatis.danboorugallery.NewHostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        ///*from w w  w  .  jav  a 2  s . co  m*/
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        Intent intent = new Intent(this, PostListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, intent);
        return true;
    }

    Fragment fragment = getFragmentManager().findFragmentById(R.id.new_host_inputs_container);
    if (fragment != null)
        return fragment.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
    return super.onOptionsItemSelected(item);
}