예제 #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
      case R.id.alpha:
        Collections.sort(trailList, Trail.TrailComparatorName);
        trailAdapter.notifyDataSetChanged();
        return true;
      case R.id.length:
        Collections.sort(trailList, Trail.TrailComparatorLength);
        trailAdapter.notifyDataSetChanged();
        return true;

      default:
        // If we got here, the user's action was not recognized.
        // Invoke the superclass to handle it.
        return super.onOptionsItemSelected(item);
    }
  }
예제 #2
0
  // search trails for the query string
  public void performSearch(String query) {
    trailList.clear();

    // check each trail's title, birds
    for (Map.Entry<String, Trail> entry : map.entrySet()) {
      String title = entry.getKey();
      String birds = entry.getValue().birdText();
      Boolean inTitle = title.toLowerCase().contains(query.toLowerCase());
      Boolean inBirds = birds.toLowerCase().contains(query.toLowerCase());
      if (inBirds || inTitle) {
        trailList.add(entry.getValue());
      }
    }
    Collections.sort(trailList, Trail.TrailComparatorName);
    trailAdapter.notifyDataSetChanged();
  }