예제 #1
0
  @Override
  public boolean onCreateOptionsMenu(final Menu menu) {

    getMenuInflater().inflate(R.menu.menu_search, menu);

    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));

    mSearchView.setOnQueryTextListener(this);
    mSearchView.setQueryHint(getString(R.string.search_library));

    mSearchView.setIconifiedByDefault(false);
    mSearchView.setIconified(false);

    MenuItemCompat.setOnActionExpandListener(
        menu.findItem(R.id.menu_search),
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            finish();
            return false;
          }
        });

    menu.findItem(R.id.menu_search).expandActionView();
    return super.onCreateOptionsMenu(menu);
  }
예제 #2
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_words, menu);

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    MenuItemCompat.setOnActionExpandListener(
        searchMenuItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            updateData();
            return true;
          }
        });

    mSearchView = (SearchView) searchMenuItem.getActionView();
    mSearchView.setQueryHint(getString(R.string.search_hint));

    if (mFilterText != null) {
      String query = mFilterText;
      searchMenuItem.expandActionView();
      mSearchView.setQuery(query, true);
      mSearchView.clearFocus();
    }
    setSearchViewTextChangeListener();
  }
예제 #3
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_bus_stops, menu);

    final MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setOnQueryTextListener(this);

    MenuItemCompat.setOnActionExpandListener(
        item,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            return true; // Return true to collapse action view
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            // Do something when expanded
            return true; // Return true to expand action view
          }
        });
    return true;
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);

    MenuItem item = menu.findItem(R.id.action_search);
    SearchView itemSearch = (SearchView) item.getActionView();
    itemSearch.setOnQueryTextListener(onQueryTextListener);
    itemSearch.setQueryHint(getString(R.string.action_search));

    MenuItemCompat.setOnActionExpandListener(
        item,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            return true;
          }
        });

    return super.onCreateOptionsMenu(menu);
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.findItem(R.id.action_search);
    if (TextUtils.isEmpty(currentCity)) {
      menuItem.setVisible(false);
    } else {
      menuItem.setVisible(true);
      MenuItemCompat.setOnActionExpandListener(
          menuItem,
          new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
              if (listView != null && searchAdapter != null) {
                listView.setAdapter(searchAdapter);
                searchAdapter.reload("");
                initActionView(item);
                searchView.requestFocus();
                mFootUpdate.dismiss();
              }
              return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
              if (listView != null && chooseAdapter != null) {
                listView.setAdapter(chooseAdapter);
              }
              return true;
            }
          });
    }
    return super.onCreateOptionsMenu(menu);
  }
예제 #6
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu
    getMenuInflater().inflate(R.menu.main, menu);

    mSearchMenuItem = menu.findItem(R.id.menu_act_filter);
    MenuItemCompat.setOnActionExpandListener(
        mSearchMenuItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem menuItem) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            notifyQueryChange("");
            return true;
          }
        });

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchMenuItem);
    searchView.setOnQueryTextListener(this);
    searchView.setSubmitButtonEnabled(true);
    searchView.setQueryHint(getString(R.string.search));

    mRefreshAnim.setMenuItem(menu.findItem(R.id.menu_act_refresh));
    return super.onCreateOptionsMenu(menu);
  }
예제 #7
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnQueryTextListener(this);
    MenuItemCompat.setOnActionExpandListener(
        menu.findItem(R.id.action_search),
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            mPreviousList = new ArrayList<Track>(mTracks);
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            getTracks(mPreviousList);
            return true;
          }
        });

    mSoundcloudLink = (TextView) menu.findItem(R.id.soundcloud_url).getActionView();
    mSoundcloudLink.setTextIsSelectable(true);

    return true;
  }
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);
   inflater.inflate(R.menu.menu_select_program, menu);
   MenuItem item = menu.findItem(R.id.action_search);
   SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
   MenuItemCompat.setOnActionExpandListener(item, this);
   searchView.setOnQueryTextListener(this);
   searchView.setOnQueryTextFocusChangeListener(this);
 }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mToolbar.inflateMenu(R.menu.menu_search);
    mToolbar.inflateMenu(R.menu.menu_others);

    RelativeLayout progressBar = (RelativeLayout) getActivity().findViewById(R.id.progressBarFetch);
    progressBar.setVisibility(View.GONE);

    searchButton = mToolbar.getMenu().findItem(R.id.action_search);
    searchButton.expandActionView();

    bigFloatingActionButton.hide();

    searchView = (SearchView) searchButton.getActionView();
    MenuItemCompat.setOnActionExpandListener(
        searchButton,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            bigFloatingActionButton.show();
            return true;
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            bigFloatingActionButton.hide();
            return true;
          }
        });
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            if (query.length() <= 2) {
              Toast.makeText(getActivity(), R.string.please_inset_more, Toast.LENGTH_SHORT).show();
            } else {
              initData(query);
              searchView.clearFocus();
              bigFloatingActionButton.show();
            }
            // searchButton.collapseActionView(); //ToDO
            return true;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            // mAdapter.filter(newText); //ToDO
            return true;
          }
        });

    setList();
  }
  @SuppressWarnings("ConstantConditions")
  private void initSearchView(final MenuItem searchMenuItem) {
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setQueryHint(getString(R.string.hint_enter_user_name));
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {

          @Override
          public boolean onQueryTextSubmit(final String s) {
            final String nickName = s.trim();
            if (USER_NAME_PATTERN.matcher(nickName).matches()) {
              MenuItemCompat.collapseActionView(searchMenuItem);
              onUserNickSelected(nickName);
            }
            return true;
          }

          @Override
          public boolean onQueryTextChange(final String s) {
            final String nickName = s.trim();
            if (USER_NAME_PATTERN.matcher(nickName).matches()) {
              onUserNickSelected(nickName);
            }
            return true;
          }
        });
    MenuItemCompat.setOnActionExpandListener(
        searchMenuItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(final MenuItem item) {
            mExpandMenu = true;
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(final MenuItem item) {
            mExpandMenu = false;
            return true;
          }
        });
    if (mExpandMenu) {
      MenuItemCompat.expandActionView(searchMenuItem);
      ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
          .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS);
    } else {
      MenuItemCompat.collapseActionView(searchMenuItem);
    }
  }
  private void setUpSearchView(final Menu menu) {
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setQueryHint(getString(R.string.contact_search_hint));

    searchView.setOnCloseListener(
        new SearchView.OnCloseListener() {
          @Override
          public boolean onClose() {
            menu.findItem(R.id.action_search).collapseActionView();
            return true;
          }
        });

    MenuItemCompat.setOnActionExpandListener(
        menu.findItem(R.id.action_search),
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            searchView.requestFocus();
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                .toggleSoftInput(
                    InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            searchView.setQuery("", true);
            searchView.clearFocus();
            return true;
          }
        });

    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            return false;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            Fragment fragmentById = getSupportFragmentManager().findFragmentById(R.id.container);
            ((ContactListFragment) fragmentById).getFilterableAdapter().getFilter().filter(newText);
            return true;
          }
        });
  }
예제 #12
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_search, menu);

    searchMenuItem = menu.findItem(R.id.action_search); // 在菜单中找到对应控件的item
    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {

          @Override
          public boolean onQueryTextSubmit(String query) {
            key = query;
            mPresenter.getSearchResultList(query);
            saveSearchHistory(query);
            return false;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
              if (mListPopupWindow.isShowing()) mListPopupWindow.dismiss();
              initTagGroup();
            } else {
              mPresenter.getAutoCompleteList(newText);
            }
            return false;
          }
        });
    search(key); // 外部调用搜索,则打开页面立即进行搜索
    MenuItemCompat.setOnActionExpandListener(
        searchMenuItem,
        new MenuItemCompat.OnActionExpandListener() { // 设置打开关闭动作监听
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            initTagGroup();
            return true;
          }
        });
    return true;
  }
예제 #13
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    SearchView view = (SearchView) MenuItemCompat.getActionView(item);

    MenuItemCompat.setOnActionExpandListener(
        item,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            getSupportFragmentManager().popBackStack();
            return true;
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
              getSupportFragmentManager()
                  .beginTransaction()
                  .replace(R.id.container, (Fragment) searchView)
                  .addToBackStack(null)
                  .commit();
            }
            return true;
          }
        });

    view.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            return false;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            if (newText.length() > 2) {
              searchView.setKeyword(newText);
            }
            return true;
          }
        });
    return true;
  }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Setup search button
    mSearchItem = menu.findItem(R.id.m_search);
    mSearchView = (SearchView) mSearchItem.getActionView();
    mSearchView.setIconifiedByDefault(true);

    mSearchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            filter(query);
            mSearchView.clearFocus();
            return true;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            mFilterText = newText;
            filter(newText);
            return true;
          }
        });
    MenuItemCompat.setOnActionExpandListener(
        mSearchItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            filter(null);
            return true; // Return true to collapse action view
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true; // Return true to expand action view
          }
        });
    if (mPreviousQuery != null && !mPreviousQuery.isEmpty()) {
      search(mPreviousQuery);
      filter(mPreviousQuery);
      mSearchView.clearFocus();
    }
  }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.preferences_fragment, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchView.setQueryHint(getString(R.string.action_search_preference));
    mSearchView.setOnQueryTextListener(
        new OnQueryTextListener() {

          @Override
          public boolean onQueryTextSubmit(String s) {
            Ui.hideSoftKeyboard(getActivity(), mSearchView);
            mSearchView.clearFocus();
            return true;
          }

          @Override
          public boolean onQueryTextChange(String s) {
            if (mSearchView.hasFocus()) {
              return updateFilter(s);
            } else {
              return false;
            }
          }
        });

    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem arg0) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem arg0) {
            return updateFilter(null);
          }
        });
    super.onCreateOptionsMenu(menu, inflater);
  }
예제 #16
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);

    MenuItem menuItem = menu.findItem(R.id.action_search);
    menuItem.expandActionView();
    MenuItemCompat.setOnActionExpandListener(
        menuItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return false;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            SearchActivity.this.finish();
            return false;
          }
        });
    searchView = (SearchView) menuItem.getActionView();
    searchView.setQueryHint(this.getResources().getString(R.string.action_search));
    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          private TextView textView = (TextView) findViewById(R.id.text_query_search);

          @Override
          public boolean onQueryTextSubmit(String query) {
            inputMethodManager.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            return true;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            textView.setText(newText);
            return true;
          }
        });
    this.getTypeSearch();
    return true;
  }
예제 #17
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.app, menu);

    mSearchItem = menu.findItem(R.id.search);
    final SearchView search = $(MenuItemCompat.getActionView(mSearchItem));
    search.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String query) {
            return false;
          }

          @Override
          public boolean onQueryTextChange(String query) {
            mAdapter.getFilter().filter(query);
            return true;
          }
        });

    search.setIconified(true);

    MenuItemCompat.setOnActionExpandListener(
        mSearchItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            showHomeAsUp();
            search.setIconified(false);
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem p1) {
            hideHomeAsUp();
            search.setQuery("", false);
            search.setIconified(true);
            return true;
          }
        });
  }
  @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, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {
          @Override
          public boolean onQueryTextSubmit(String s) {
            return true;
          }

          @Override
          public boolean onQueryTextChange(String s) {
            filterListAdapter(s);
            return true;
          }
        });

    // When using the support library, the setOnActionExpandListener() method is
    // static and accepts the MenuItem object as an argument
    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            refreshListAdapter();
            return true;
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }
        });
    return super.onCreateOptionsMenu(menu);
  }
예제 #19
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.main_action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    setupSearchView();
    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            // SearchView 열릴때
            refreshHandler.removeCallbacks(refreshRunnable); // 새로고침 중단
            chooseList = false;
            searchList.clear(); // SearchList 비우고
            dinerListView.setAdapter(mSearchAdapter); // ListView의 Adapter 다시 세팅
            dinerListView.setOnItemClickListener(mainActivity);
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            // SearchView 닫힐때
            chooseList = true;
            dinerListView.setAdapter(mAdapter); // ListView Adapter 다시 세팅
            dinerListView.setOnItemClickListener(mainActivity);
            fetchDiners();
            refreshRunnable.run(); // 새로고침 시작
            return true;
          }
        });
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null)
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
  }
예제 #20
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    inflater.inflate(R.menu.menu_main_search, menu); // removed to not double the menu items
    MenuItem item = menu.findItem(R.id.menu_search);
    SearchView sv =
        new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext());
    MenuItemCompat.setShowAsAction(
        item,
        MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    MenuItemCompat.setActionView(item, sv);
    sv.setOnQueryTextListener(this);
    sv.setIconifiedByDefault(false);
    sv.setOnSearchClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {}
        });

    MenuItemCompat.setOnActionExpandListener(
        item,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            return true; // Return true to collapse action view
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            // Do something when expanded
            return true; // Return true to expand action view
          }
        });

    super.onCreateOptionsMenu(menu, inflater);
  }
예제 #21
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_info, menu);
    MenuItem menuItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

    MenuItemCompat.setOnActionExpandListener(
        menuItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            getSupportFragmentManager().popBackStack();
            return true; // Return true to collapse action view
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            // Do something when expanded
            getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, petsListFragment)
                .addToBackStack("PetsListFragment")
                .commit();
            return true; // Return true to expand action view
          }
        });
    // Get the SearchView and set the searchable configuration
    // Assumes current activity is the searchable activity
    //        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default
    searchView.setOnQueryTextListener(this);

    return true;
  }
예제 #22
0
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_manage_inserts, menu);

    final MenuItem searchItem = menu.findItem(R.id.menu_search_inserts);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getString(R.string.insert_query_hint));
    searchView.setOnQueryTextListener(this);

    searchView.setOnQueryTextFocusChangeListener(
        new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
              MenuItemCompat.collapseActionView(searchItem);
              searchView.setQuery("", false);
            }
          }
        });

    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new MenuItemCompat.OnActionExpandListener() {
          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            adapter.refreshAdapter();
            return true;
          }
        });
  }
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public void setupSearch(Menu menu) {
    // bail early on unsupported devices
    if (Build.VERSION.SDK_INT < 11) {
      return;
    }

    mSearchItem = menu.findItem(R.id.search);
    MenuItemCompat.setOnActionExpandListener(
        mSearchItem,
        new OnActionExpandListener() {

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            // always allow expansion of the search action view
            return mCurrentPageId == R.id.task_group_search;
          }

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            // return to previous view
            if (mPreviousPagePosition >= 0 && mCurrentPageId == R.id.task_group_search) {
              mViewPager.setCurrentItem(mPreviousPagePosition);
              mCurrentPageId = mPagerAdapter.getPageId(mPreviousPagePosition);
            }
            return mPreviousPagePosition >= 0 || mCurrentPageId != R.id.task_group_search;
          }
        });
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (null != searchManager) {
      searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    searchView.setQueryHint(getString(R.string.menu_search_hint));
    searchView.setIconified(true);
    searchView.setOnQueryTextListener(
        new OnQueryTextListener() {

          @Override
          public boolean onQueryTextSubmit(String query) {
            // persist current search
            mSearchHistoryHelper.commitSearch();
            mHandler.post(mSearchUpdater);
            return true;
          }

          @Override
          public boolean onQueryTextChange(String query) {
            if (mCurrentPageId != R.id.task_group_search) {
              return true;
            }

            mHandler.removeCallbacks(mSearchUpdater);
            if (query.length() > 0) {
              mSearchHistoryHelper.updateSearch(query);
              mHandler.postDelayed(mSearchUpdater, SEARCH_UPDATE_DELAY);
            } else {
              mSearchHistoryHelper.removeCurrentSearch();
              mHandler.post(mSearchUpdater);
            }
            return true;
          }
        });

    if (mAutoExpandSearchView) {
      mSearchItem.expandActionView();
    }
  }
  private void _defineSearchView(Menu menu) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Theme the SearchView's AutoCompleteTextView drop down. For some reason this wasn't working in
    // styles.xml
    SearchView.SearchAutoComplete autoCompleteTextView =
        (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

    if (autoCompleteTextView != null) {
      autoCompleteTextView.setDropDownBackgroundResource(android.R.color.white);
      // set Enable Spelling Suggestions
      autoCompleteTextView.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
      int color = Color.parseColor("#ffffffff");
      Drawable drawable = autoCompleteTextView.getDropDownBackground();
      drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);

      autoCompleteTextView.setDropDownBackgroundDrawable(drawable);
      autoCompleteTextView.setTextColor(
          getResources().getColor(R.color.auto_complete_text_view_text_color));
    }

    MenuItemCompat.setOnActionExpandListener(
        searchItem,
        new MenuItemCompat.OnActionExpandListener() {

          @Override
          public boolean onMenuItemActionCollapse(MenuItem item) {
            Log.d(TAG, "onMenuItemActionCollapse");
            return true;
          }

          @Override
          public boolean onMenuItemActionExpand(MenuItem item) {
            Log.d(TAG, "onMenuItemActionExpand");
            return true;
          }
        });
    searchView.setOnSuggestionListener(
        new SearchView.OnSuggestionListener() {
          @Override
          public boolean onSuggestionSelect(int position) {
            Log.d(TAG, "onSuggestionSelect:" + position);
            return false;
          }

          @Override
          public boolean onSuggestionClick(int position) {
            Log.d(TAG, "onSuggestionClick:" + position);
            try {
              CursorAdapter c = searchView.getSuggestionsAdapter();
              if (c != null) {
                Cursor cur = c.getCursor();
                cur.moveToPosition(position);

                String cardID = cur.getString(cur.getColumnIndex(BaseColumns._ID));
                Log.d(TAG, "cardID:" + cardID);
                String query =
                    cur.getString(cur.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
                Log.d(TAG, "query:" + query);
                int insertSuggesstionResults = learnApiImplements._insertSuggesstion(cardID);
                Log.d(
                    TAG,
                    "insertSuggesstionResults "
                        + ((insertSuggesstionResults == -1) ? " OK" : " Fails"));
                _displayCard(cardID);

                // call back actionbar
                searchItem.collapseActionView();
              } else {
                Log.d(TAG, "NUll searchView.getSuggestionsAdapter()");
              }
            } catch (Exception e) {
              LazzyBeeShare.showErrorOccurred(context, "_defineSearchView", e);
            }
            return true;
          }
        });
  }