title: Search item in edittext from listview showing wrong result
body: <p>Trying to search a listview items using edittext, where clicking on searched item returning wrong position.</p>
  
  <p>Supposed i search "C" from given list where list item is as follows "A","B","C","D","CC", and got the correct search result but once making the click on search item, It returning the wrong item position. </p>
  
  <p>Here Edittext addTextChangedListener :</p>
  
  <pre><code>edtSearch.addTextChangedListener(new TextWatcher() {
  
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  adapter.getFilter().filter(s);
                  adapter.notifyDataSetChanged();
  
              }
  
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
  
              }
  
              public void afterTextChanged(Editable s) {
              }
          });
      }
  </code></pre>
  
  <blockquote>
    <p><strong>Complete class code:</strong></p>
  </blockquote>
  
  <pre><code>    package com.tomar.xyz;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class Tabtwo extends Activity implements OnItemClickListener {
  
      ListView listView;
      TextView txt;
  
      ArrayAdapter&lt;String&gt; adapter;
  
      // Search EditText
      EditText edtSearch;
  
      // Array of strings storing country names
      String[] countries = new String[] { "Admin Cost", "Affinity Diagram",
              "Analyse", "Apprasal Costs", "Assessment of Stakeholders",
                };
  
      // Array of integers points to images stored in /res/drawable-ldpi/
      int[] flags = new int[] { R.drawable.admin, R.drawable.affinity,
              R.drawable.analysis, R.drawable.appraisal, R.drawable.assessment,
                };
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.tabtwo);
  
          // Each row in the list stores country name, currency and flag
          List&lt;HashMap&lt;String, String&gt;&gt; aList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          for (int i = 0; i &lt; 4; i++) {
              HashMap&lt;String, String&gt; hm = new HashMap&lt;String, String&gt;();
              hm.put("txt", countries[i]);
  
              hm.put("flag", Integer.toString(flags[i]));
              aList.add(hm);
          }
  
          // Keys used in Hashmap
          String[] from = { "flag", "txt" };
  
          // Ids of views in listview_layout
          int[] to = { R.id.flag, R.id.txt };
  
          // Instantiating an adapter to store each items
          // R.layout.listview_layout defines the layout of each item
          final SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),
                  aList, R.layout.listview_layout, from, to);
  
          // Getting a reference to listview of main.xml layout file
          ListView listView = (ListView) findViewById(R.id.listview);
          edtSearch = (EditText) findViewById(R.id.Search_box);
          txt = (TextView) findViewById(R.id.txt);
          listView.setOnItemClickListener(this);
          // Setting the adapter to the listView
          listView.setAdapter(adapter);
  
          listView.setTextFilterEnabled(true);
          listView.setOnItemClickListener(this);
          edtSearch.addTextChangedListener(new TextWatcher() {
  
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  adapter.getFilter().filter(s);
                  adapter.notifyDataSetChanged();
  
              }
  
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
  
              }
  
              public void afterTextChanged(Editable s) {
              }
          });
      }
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position,
              long arg3) {
          // TODO Auto-generated method stub
          if (position == 0) {
              Intent int0 = new Intent(getApplicationContext(), Admincost.class);
              startActivity(int0);
          }
  
          if (position == 1) {
              Intent int1 = new Intent(getApplicationContext(), Affinity.class);
              startActivity(int1);
          }
          if (position == 2) {
              Intent int2 = new Intent(getApplicationContext(), Analyse.class);
              startActivity(int2);
          }
  
          if (position == 3) {
              Intent int3 = new Intent(getApplicationContext(),
                      ApprasalCosts.class);
              startActivity(int3);
          }
          if (position == 4) {
              Intent int1 = new Intent(getApplicationContext(), Assessment.class);
              startActivity(int1);
          } }
      }
  }
  </code></pre>