title: Retaing the original list position after search filter in custom listview uses Array adapter filterable
body: <p>I have a Custom listView which is filterable. It gets filter currently. But after filtering the original position get lost and for that when I set <code>onClickListener</code> it is showing the wrong result. Is there any way to get the original position? </p>
  
  <p><strong>Search Adapter</strong></p>
  
  <pre><code>public class SearchAdapter extends ArrayAdapter implements Filterable{
  
  private List&lt;word&gt; allModelItemsArray;
  private List&lt;word&gt; filteredModelItemsArray;
  private Activity context;
  private ModelFilter filter;
  private LayoutInflater inflator;
  MediaPlayer mediaPlayer;
  private List&lt;word&gt; list;
  
  public SearchAdapter(Activity context, List&lt;word&gt; list) {
      super(context, R.layout.search_row, list);
      this.context = context;
      this.allModelItemsArray = new ArrayList&lt;word&gt;();
      this.list = list;
      allModelItemsArray.addAll(list);
      this.filteredModelItemsArray = new ArrayList&lt;word&gt;();
      filteredModelItemsArray.addAll(allModelItemsArray);
      inflator = context.getLayoutInflater();
      getFilter();
  }
  @Override
  public Filter getFilter() {
      if (filter == null){
          filter  = new ModelFilter();
      }
      return filter;
  }
  
  static class ViewHolder {
      protected TextView text;
      protected TextView translatedText;
      protected TextView pronounce;
  
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View view = null;
      Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/NotoSans-Regular.ttf");
      word m = filteredModelItemsArray.get(position);
  
      ViewHolder viewHolder = null;
      if (convertView == null) {
  
          view = inflator.inflate(R.layout.search_row, null);
          viewHolder = new ViewHolder();
          viewHolder.text = (TextView) view.findViewById(R.id.list_view_search_words);
          viewHolder.text.setTypeface(font);
  
          viewHolder.translatedText = (TextView) view.findViewById(R.id.translated_text);
          viewHolder.translatedText.setTypeface(font);
          viewHolder.pronounce = (TextView) view.findViewById(R.id.pronounce);
          viewHolder.pronounce.setTypeface(font);
  
  
          view.setTag(viewHolder);
      } else {
          view = convertView;
          viewHolder = ((ViewHolder) view.getTag());
      }
      viewHolder.text.setText(m.getMainText());
      viewHolder.translatedText.setText(m.getTranslationText());
      viewHolder.pronounce.setText(m.getPronunciation_in_english());
      /*get full sound file name*/
      Integer fileNameLength = m.getAudio().toString().length();
      String fileName = m.getAudio().toString();
      final String soundFile = fileName.substring(0,fileNameLength - 4);
      final ImageView imgPlay = (ImageView) view.findViewById(R.id.phraselist_play_audio);
      imgPlay.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              if (mediaPlayer == null) {
                  View parentRow = (View) v.getParent();
                  ListView listView = (ListView) parentRow.getParent();
                  final int position = listView.getPositionForView(parentRow);
  
                  try {
                      Uri mp3 = Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + soundFile);
                      mediaPlayer = new MediaPlayer();
                      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                      mediaPlayer.setDataSource(context, mp3);
                      mediaPlayer.prepare(); // might take long! (for buffering, etc)
                      mediaPlayer.start();
                      imgPlay.setImageResource(R.drawable.playactive);
                      // mediaPlayer.setOnCompletionListener(onCompletionListener);
                      mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                          @Override
                          public void onCompletion(MediaPlayer mp) {
                              mediaPlayer.release();
                              mediaPlayer = null;
                              imgPlay.setImageResource(R.drawable.playinactive);
                          }
                      });
                  } catch (IllegalArgumentException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (SecurityException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IllegalStateException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
  
          }
      });
  
      return view;
  }
  
  private class ModelFilter extends Filter
  {
  
      @Override
      protected FilterResults performFiltering(CharSequence constraint) {
  
          constraint = constraint.toString().toLowerCase();
          FilterResults result = new FilterResults();
          if(constraint != null &amp;&amp; constraint.toString().length() &gt; 0)
          {
              ArrayList&lt;word&gt; filteredItems = new ArrayList&lt;word&gt;();
  
              for(int i = 0, l = allModelItemsArray.size(); i &lt; l; i++)
              {
                  word m = allModelItemsArray.get(i);
                  if(m.getMainText().toLowerCase().contains(constraint))
                      filteredItems.add(m);
              }
              result.count = filteredItems.size();
              result.values = filteredItems;
          }
          else
          {
              synchronized(this)
              {
                  result.values = allModelItemsArray;
                  result.count = allModelItemsArray.size();
  
              }
          }
          return result;
      }
  
      @SuppressWarnings("unchecked")
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
  
          filteredModelItemsArray = (ArrayList&lt;word&gt;)results.values;
          notifyDataSetChanged();
          clear();
          for(int i = 0, l = filteredModelItemsArray.size(); i &lt; l; i++)
              add(filteredModelItemsArray.get(i));
          notifyDataSetInvalidated();
      }
    }
  }                                      
  </code></pre>
  
  <p><strong>Search List Activity (onResume function)</strong></p>
  
  <pre><code>protected void onResume(){
      super.onResume();
  
      GlobalState state = ((GlobalState) getApplicationContext());
      state.doAction();
  
      wordDb = new wordDB(SearchListActivity.this);
      paymentDb = new paymentDB(SearchListActivity.this);
      //getAllWords();
  
  
      final ArrayList&lt;word&gt; words = new ArrayList&lt;word&gt;();
  
      Cursor row;
  
      Integer checkPayment = paymentDb.CheckTable();
  
      /*If free not purchased*/
      if(checkPayment == 0)
      {
          row = wordDb.selectWordList("0");
      }
      else
      {
          row = wordDb.selectAllWord();
      }
  
  
      row.moveToFirst();
  
      while (!row.isAfterLast()) {
  
  
          words.add( new word(row.getString(0),row.getString(1),row.getString(2),row.getString(3),row.getString(4),row.getString(5),row.getString(6),row.getString(7),row.getString(8),row.getString(9)));
          row.moveToNext();
      }
      row.close();
      final SearchAdapter adapter = new SearchAdapter(SearchListActivity.this, words);
      final ListView listView = (ListView) findViewById(R.id.search_list_view_word);
      listView.setAdapter(adapter);
      final EditText etSearch = (EditText) findViewById(R.id.etSearch);
      // Add Text Change Listener to EditText
      etSearch.addTextChangedListener(new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
              // Call back the Adapter with current character to Filter
              adapter.getFilter().filter(s.toString());
              adapter.notifyDataSetChanged();
              listView.setAdapter(adapter);
          }
  
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count,int after) {
          }
  
          @Override
          public void afterTextChanged(Editable s) {
              if(s.length()==0){
  
              }
  
          }
      });
  
  
      ListView searchListView;
      searchListView = (ListView)findViewById(R.id.search_list_view_word);
      searchListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              Object o = parent.getItemAtPosition(position);
              word_obj = (word) o;
  
              if (Integer.valueOf(word_obj.getCategoryId()) &gt;= 0) {
                  Intent myIntent = new Intent(SearchListActivity.this, WordDetailsActivity.class);
                  myIntent.putExtra("word_obj", word_obj);
                  myIntent.putExtra("position", position);
  
  
                  //Log.d("id",String.valueOf(id));
                  //Log.d("getitem", String.valueOf(adapter.getItemId(position)));
                  //words.get(words.indexOf(searchAdapter.getItemId(position)));
  
  
  
  
                  myIntent.putExtra("currentClickedId", word_obj.getCsvWordId().toString());
                  myIntent.putExtra("favouriteFlag", 0);
                  myIntent.putExtra("searchFlag", 1);
                  myIntent.putExtra("searchString", etSearch.getText().toString());
                  SearchListActivity.this.startActivity(myIntent);
              }
  
          }
      });
  
  
  
  }
  </code></pre>