Example usage for android.view MenuItem getActionView

List of usage examples for android.view MenuItem getActionView

Introduction

In this page you can find the example usage for android.view MenuItem getActionView.

Prototype

public View getActionView();

Source Link

Document

Returns the currently set action view for this menu item.

Usage

From source file:com.example.snowball.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_websearch);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint("///");
    searchView.setQueryRefinementEnabled(false);
    // SearchView
    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.gcncouponalert.app.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    //Spinner spinner = (Spinner) findViewById(R.id.coupons_spinner);
    MenuItem item = menu.findItem(R.id.coupons_spinner);
    Spinner spinner = (Spinner) item.getActionView();
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.coupon_filter_options,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from   w w  w  .  ja  v a2 s. c  o m*/
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.d(LOG_TAG, " onItemSelected: " + position + "; " + id);
            CouponsFragment ff = (CouponsFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.fragment_forecast);
            if (null != ff) {
                ff.onSpinnerChanged(position);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

            // sometimes you need nothing here
        }
    });
    //MenuItem item = menu.findItem(R.id.coupons_spinner);
    //Spinner spinner =(Spinner) item.getActionView();
    //setupSpinner(spinner);
    //String[] items={"All","Favorites"};
    //wrap the items in the Adapter
    //ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,items);
    //assign adapter to the Spinner
    //spinner.setAdapter(adapter);

    //MenuItem item = menu.findItem(R.id.coupons_spinner);
    //Spinner spinner = (Spinner) MenuItemCompat.getActionView(item);
    //spinner.setAdapter(adapter); // set the adapter to provide layout of rows and content
    //s.setOnItemSelectedListener(onItemSelectedListener); // set the listener, to perform actions based on item selection
    return true;
}

From source file:org.intermine.app.activity.TemplateResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.templates_results_menu, menu);
    MenuItem menuItem = menu.findItem(R.id.templates_results_search_action);
    MenuItemCompat.setOnActionExpandListener(menuItem, this);
    mSearchView = (SearchView) menuItem.getActionView();
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setQueryHint(getString(R.string.template_search_hint));
    return true;/*from  w ww.ja  va 2 s .c o m*/
}

From source file:com.saarang.samples.apps.iosched.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(com.saarang.samples.apps.iosched.R.menu.search, menu);
    final MenuItem searchItem = menu.findItem(com.saarang.samples.apps.iosched.R.id.menu_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) searchItem.getActionView();
        mSearchView = view;/*from  w  w w  . j ava2  s  .  c o m*/
        if (view == null) {
            LogUtils.LOGW(TAG, "Could not set up search view, view is null.");
        } else {
            view.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            view.setIconified(false);
            view.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    view.clearFocus();
                    if ("zzznotif".equals(s)) {
                        (new ShowFeedbackNotificationAction()).run(SearchActivity.this, null);
                    }
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    if (null != mSessionsFragment) {
                        mSessionsFragment.requestQueryUpdate(s);
                    }
                    return true;
                }
            });
            view.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    finish();
                    return false;
                }
            });
        }

        if (!TextUtils.isEmpty(mQuery)) {
            view.setQuery(mQuery, false);
        }
    }
    return true;
}

From source file:de.flyingsnail.ipv6droid.android.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_connect:
        startVPN(item.getActionView());
        return true;

    case R.id.action_disconnect:
        stopVPN();//from  w  ww.  j  a v  a2  s .  co m
        return true;

    case R.id.action_settings:
        openSettings();
        return true;

    case R.id.action_help:
        openHelp();
        return true;

    default:
        return false;
    }
}

From source file:com.thelastcrusade.soundstream.CoreActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    getMenuInflater().inflate(R.menu.search_menu, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) searchItem.getActionView();

    if (searchView != null) {
        searchView.setSearchableInfo(/*from   w  w w .j  a va2s  .  c om*/
                searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setFocusable(true);
                v.requestFocusFromTouch();
            }
        });

        if (isConnectActive()) {
            searchItem.setVisible(false);
        }
    }
    return true;
}

From source file:com.aboveware.actionbar.honeycomb.ActionBarHelperHoneycomb.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mOptionsMenu = menu;/*  w  w  w . j a va2  s  .  c om*/
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null) {
        final SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setIconifiedByDefault(false);
        searchView.setSubmitButtonEnabled(true);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                return iDocument.searchSubmit(query);
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return iDocument.search(newText);
            }
        });
    }
    boolean returnValue = super.onCreateOptionsMenu(menu);
    if (shouldBeRefreshing) {
        setRefreshActionItemState(true);
    }
    shouldBeRefreshing = false;
    return returnValue;
}

From source file:org.schabi.newpipe.VideoItemListActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.menu = menu;
    MenuInflater inflater = getMenuInflater();
    if (mode != PRESENT_VIDEOS_MODE && findViewById(R.id.videoitem_detail_container) == null) {
        inflater.inflate(R.menu.videoitem_list, menu);
        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setFocusable(false);//from   w  w w  . j  a v a2s  .  co m
        searchView.setOnQueryTextListener(new SearchVideoQueryListener());
        suggestionListAdapter = new SuggestionListAdapter(this);
        searchView.setSuggestionsAdapter(suggestionListAdapter);
        searchView.setOnSuggestionListener(new SearchSuggestionListener(searchView));
        if (!searchQuery.isEmpty()) {
            searchView.setQuery(searchQuery, false);
            searchView.setIconifiedByDefault(false);
        }
    } else if (videoFragment != null) {
        videoFragment.onCreateOptionsMenu(menu, inflater);
    } else {
        inflater.inflate(R.menu.videoitem_two_pannel, menu);
    }

    return true;
}

From source file:com.giltesa.taskcalendar.activity.Main.java

/**
 * Se carga el ActionBar y se recupera el Campo de Busqueda.
 *//* w  ww .j  ava2 s  .co m*/
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    inflater.inflate(R.menu.main_actionbar, menu);

    //Cuadro de busqueda
    MenuItem searchItem = menu.findItem(R.id.main_actionbar_search);
    mSearchView = (SearchView) searchItem.getActionView();
    setupSearchView(searchItem);

    return true;
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_category, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search_category);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(/*  w  w  w .  ja  v a2  s  .c  o m*/
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mCategoryDbAdapter.getAll();
            final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                if (mCategoryAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_category),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsCategory.setText(styledNoResults);
                    mTextNoResultsCategory.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsCategory.setVisibility(View.GONE);
                }
            } else {
                mCategoryAdapter.swapCursor(cursor);
                mTextNoResultsCategory.setVisibility(View.GONE);
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });
}