예제 #1
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.search_orders_options_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconified(false);
    searchView.setIconifiedByDefault(false);
    searchView.setClickable(true);
    searchView.setOnQueryTextListener(this);
    searchView.setOnClickListener(this);
    moveSearchIconFromBeginToEnd(searchView);

    return true;
  }
예제 #2
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_hotel_list, menu);

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

    searchView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String query = searchView.getQuery().toString();

            ParseQuery<ParseObject> hotelQuery = ParseQuery.getQuery("Hotel");

            if (!query.isEmpty()) {
              hotelQuery.whereContains("Name", query);
              hotelQuery.whereContains("LocationName", query);
              hotelQuery.whereContains("Cuisines", query);
            }

            hotelQuery.findInBackground(
                new FindCallback<ParseObject>() {
                  public void done(List<ParseObject> hotelList, ParseException e) {
                    if (e == null) {
                      hotelAdapter.clear();

                      for (int i = 0; i < hotelList.size(); ++i) {
                        hotelAdapter.insert(hotelList.get(i), hotelAdapter.getCount());
                      }

                      hotelAdapter.notifyDataSetChanged();
                    } else {
                      Log.d("score", "Error: " + e.getMessage());
                    }
                  }
                });
          }
        });

    return super.onCreateOptionsMenu(menu);
  }