コード例 #1
0
  /**
   * Search for movies with a given word(s) in the text view
   *
   * @param view
   */
  public void search(View view) {
    movies.clear();

    // TODO: Extract search query from text view
    EditText editText1 = (EditText) findViewById(R.id.editText1);
    // TODO: Run the search thread
    movieManager.search(editText1.getText().toString());
    movies = movieManager.getMovies();
    movies.notifyObservers();
  }
コード例 #2
0
  @Override
  protected void onStart() {
    super.onStart();

    movieManager = new ESMovieManager();
    movieManager.search("*");
    movies = movieManager.getMovies();
    // movies = new Movies();
    movies.addObserver(this);
    moviesViewAdapter = new ArrayAdapter<Movie>(this, R.layout.list_item, movies);
    movieList.setAdapter(moviesViewAdapter);

    // Show details when click on a movie
    movieList.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            int movieId = movies.get(pos).getId();
            startDetailsActivity(movieId);
          }
        });

    // Delete movie on long click
    movieList.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Movie movie = movies.get(position);
            Toast.makeText(mContext, "Deleting " + movie.getTitle(), Toast.LENGTH_LONG).show();

            Thread thread = new DeleteThread(movie.getId());
            thread.start();

            return true;
          }
        });
  }