예제 #1
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_reminders, menu);

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

    if (android.os.Build.MANUFACTURER.equals("samsung")) {
      searchItem.setVisible(false);
    }

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    searchView.addOnAttachStateChangeListener(
        new View.OnAttachStateChangeListener() {

          @Override
          public void onViewDetachedFromWindow(View arg0) {
            ExpAdapter.removeFilter();
            // fix collapsed groups
            for (int i = 0; i < ExpAdapter.getGroupCount(); i++) {
              expandableListView.expandGroup(i);
            }
          }

          @Override
          public void onViewAttachedToWindow(View arg0) {
            ExpAdapter.searchStarted();
          }
        });

    searchView.setOnQueryTextListener(
        new SearchView.OnQueryTextListener() {

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

          @Override
          public boolean onQueryTextChange(String newText) {
            ExpAdapter.filter(newText);
            // fix collapsed groups
            for (int i = 0; i < ExpAdapter.getGroupCount(); i++) {
              expandableListView.expandGroup(i);
            }
            return true;
          }
        });

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

    // set & get the search button in the actionbar
    final SearchView searchView = new SearchView(mAct);

    searchView.setQueryHint(getResources().getString(R.string.video_search_hint));
    searchView.setOnQueryTextListener(
        new OnQueryTextListener() {
          //
          @Override
          public boolean onQueryTextSubmit(String query) {
            try {
              query = URLEncoder.encode(query, "UTF-8");
            } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
            }
            searchView.clearFocus();

            baseurl = searchurl + query + searchurlend;

            // if a task is active, cancel it
            if (mTask.getStatus().equals(AsyncTask.Status.RUNNING)) {
              mTask.cancel(true);
              mTask = null;
              if (mInfo.isLoading) {
                mInfo.isLoading = false;
              }
            }

            mTask = new WordpressGetTask(baseurl, true, mInfo);
            mTask.execute();
            return true;
          }

          @Override
          public boolean onQueryTextChange(String newText) {
            return false;
          }
        });

    searchView.addOnAttachStateChangeListener(
        new OnAttachStateChangeListener() {

          @Override
          public void onViewDetachedFromWindow(View arg0) {
            if (!mInfo.isLoading) {
              baseurl = pageurl;
              mTask = new WordpressGetTask(baseurl, true, mInfo);
              mTask.execute();
            }
          }

          @Override
          public void onViewAttachedToWindow(View arg0) {
            // search was opened
          }
        });

    // TODO make menu an xml item
    menu.add("search")
        .setIcon(R.drawable.ic_action_search)
        .setActionView(searchView)
        .setShowAsAction(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
  }