Esempio n. 1
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    if (getListAdapter() == mHistoryAdapter) {
      String selection = ((TextView) v.findViewById(android.R.id.text1)).getText().toString();
      mSearchText.setText(selection);
      mSearchText.setSelection(selection.length());
      mSearchText.requestFocus();
    } else if (getListAdapter() == mResultAdapter) {
      // add search text to the database (history)
      MediaDatabase db = MediaDatabase.getInstance(this);
      db.addSearchhistoryItem(mSearchText.getText().toString());

      // open media in the player
      Media item = (Media) getListAdapter().getItem(position - 1);
      if (item.getType() == Media.TYPE_VIDEO) {
        VideoPlayerActivity.start(this, item.getLocation());
      } else {
        ArrayList<String> arr = new ArrayList<String>();
        for (int i = 0; i < getListAdapter().getCount(); i++) {
          Media audioItem = (Media) getListAdapter().getItem(i);
          if (audioItem.getType() == Media.TYPE_AUDIO) arr.add(audioItem.getLocation());
        }
        AudioServiceController.getInstance().load(arr, arr.indexOf(item.getLocation()));
        AudioPlayerActivity.start(this);
      }
      super.onListItemClick(l, v, position, id);
    }
  };