title: Searchbox in Listview: always the same result
body: <p>when i use the serachbox for my Listview, i get everytime the same result. For Example:</p>
  
  <p>Car
  Flower
  Hate
  Love 
  Water</p>
  
  <p>When I typef or h or l etc. the result is Car. I worked with this example <a href="http://androidcocktail.blogspot.in/2012/04/search-custom-listview-in-android.html" rel="nofollow">http://androidcocktail.blogspot.in/2012/04/search-custom-listview-in-android.html</a></p>
  
  <p>Activity:</p>
  
  <pre><code>package de.bodprod.rettinfo;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import android.app.ListActivity;
  import android.content.Context;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  
  public class AntidotList extends ListActivity{
      ArrayList&lt;HashMap&lt;String, Object&gt;&gt; antidots;
      ArrayList&lt;HashMap&lt;String, Object&gt;&gt; antidotsResult;
      LayoutInflater inflater;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.antidotlist_layout);
          final EditText searchBox=(EditText) findViewById(R.id.EditText01);
          ListView antidotListView=(ListView) findViewById(android.R.id.list);
  
          inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
          antidots = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;();        
          DatabaseHandler db = new DatabaseHandler(getApplicationContext());
          antidots = db.getAllAntidots();
  
          antidotsResult = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;(antidots);
  
          final CustomAdapter adapter = new CustomAdapter(this, R.layout.antidotlist_layout, antidotsResult);
          antidotListView.setAdapter(adapter);
  
          searchBox.addTextChangedListener(new TextWatcher() {
              public void onTextChanged(CharSequence s, int start, int before, int count) {
                  //get the text in the EditText
                  String searchString=searchBox.getText().toString();
                  int textLength=searchString.length();
  
                  antidotsResult.clear();
  
                  for(int i=0;i&lt;antidots.size();i++){
                      String toxinname=antidots.get(i).get("toxin").toString();
                      if(textLength&lt;=toxinname.length()){
                          if(searchString.equalsIgnoreCase(toxinname.substring(0,textLength)))
                              antidotsResult.add(antidots.get(i));
                      }
                  } 
                  adapter.notifyDataSetChanged();
              }
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
              public void afterTextChanged(Editable s) {}
          });
      }
  
      private class CustomAdapter extends ArrayAdapter&lt;HashMap&lt;String, Object&gt;&gt;{
          public CustomAdapter(Context context, int textViewResourceId, ArrayList&lt;HashMap&lt;String, Object&gt;&gt; Strings) {
              super(context, textViewResourceId, Strings);
          }
          private class ViewHolder{
              TextView sqlite_id, tox_layout, antidot_layout;
          }
  
          ViewHolder viewHolder;
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              if(convertView==null){        
                  convertView=inflater.inflate(R.layout.antidotlistitem_layout, null);
                  viewHolder=new ViewHolder();
  
                  viewHolder.sqlite_id=(TextView) convertView.findViewById(R.id.sqlite_id);
                  viewHolder.tox_layout=(TextView) convertView.findViewById(R.id.tox_layout);
                  viewHolder.antidot_layout=(TextView) convertView.findViewById(R.id.antidot_layout);
  
                  convertView.setTag(viewHolder);
  
              }else{
                  viewHolder=(ViewHolder) convertView.getTag();
              }
  
              viewHolder.sqlite_id.setText(antidots.get(position).get("sql_id").toString());
              viewHolder.tox_layout.setText(antidots.get(position).get("toxin").toString());
              viewHolder.antidot_layout.setText(antidots.get(position).get("antidot").toString());
  
              return convertView;
          }
      }
  }
  </code></pre>
  
  <p>DatabaseHandler:</p>
  
  <pre><code>package de.bodprod.rettinfo;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.util.Log;
  
  public class DatabaseHandler extends SQLiteOpenHelper {
      // All Static variables
      // Database Version
      private static final int DATABASE_VERSION = 7;
  
      // Database Name
      private static final String DATABASE_NAME = "rettinfo";
  
      // Antidot table name
      private static final String TABLE_ANTIDOT = "antidotlist";
  
      // Antidot Table Columns names
      private static final String KEY_ID = "id";
      private static final String KEY_TOX = "tox";
      private static final String KEY_ANTIDOT = "antidot";
      private static final String KEY_DOS = "dos";
      private static final String KEY_KAT = "kat";
  
      public DatabaseHandler(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
      }
  
      // Creating Tables
      @Override
      public void onCreate(SQLiteDatabase db) {
          Log.d("Create: ", "Creating ..");
          String CREATE_ANTIDOT_TABLE = "CREATE TABLE " + TABLE_ANTIDOT + "("
                  + KEY_ID + " INTEGER PRIMARY KEY," + KEY_TOX + " TEXT,"
                  + KEY_ANTIDOT + " TEXT," + KEY_DOS + " TEXT," + KEY_KAT + " INTEGER" + ")";
          Log.d("Create: ", CREATE_ANTIDOT_TABLE);
          db.execSQL(CREATE_ANTIDOT_TABLE);
  
          ContentValues values = new ContentValues();
          values.put(KEY_TOX, "Alkylphosphat");
          values.put(KEY_ANTIDOT, "Atropinsulfat");
          values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min &amp;#xA; Kinder - Initial: 0,5 - 2 mg i.V. &amp;#xA; bis zum Rückgang der Bronchialsekretion");
          values.put(KEY_KAT, "1");
          db.insert(TABLE_ANTIDOT, null, values);
  
          values.put(KEY_TOX, "E605 (Alkylphosphat)");
          values.put(KEY_ANTIDOT, "Atropinsulfat");
          values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min &amp;#xA; Kinder - Initial: 0,5 - 2 mg i.V. &amp;#xA; bis zum Rückgang der Bronchialsekretion");
          values.put(KEY_KAT, "1");
          db.insert(TABLE_ANTIDOT, null, values);
  
          values.put(KEY_TOX, "DDVP (Alkylphosphat)");
          values.put(KEY_ANTIDOT, "Atropinsulfat");
          values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min &amp;#xA; Kinder - Initial: 0,5 - 2 mg i.V. &amp;#xA; bis zum Rückgang der Bronchialsekretion");
          values.put(KEY_KAT, "1");
          db.insert(TABLE_ANTIDOT, null, values);       
  
          values.put(KEY_TOX, "Sarin (Alkylphosphat)");
          values.put(KEY_ANTIDOT, "Atropinsulfat");
          values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min &amp;#xA; Kinder - Initial: 0,5 - 2 mg i.V. &amp;#xA; bis zum Rückgang der Bronchialsekretion");
          values.put(KEY_KAT, "1");
          db.insert(TABLE_ANTIDOT, null, values);         
  
          values.put(KEY_TOX, "Nervengas (Alkylphosphat)");
          values.put(KEY_ANTIDOT, "Atropinsulfat");
          values.put(KEY_DOS, "Initial: 2 - 5 mg i.V. alle 10 bis 15 Min &amp;#xA; Kinder - Initial: 0,5 - 2 mg i.V. &amp;#xA; bis zum Rückgang der Bronchialsekretion");
          values.put(KEY_KAT, "1");
          db.insert(TABLE_ANTIDOT, null, values);         
      }
  
      // Upgrading database
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          // Drop older table if existed
          db.execSQL("DROP TABLE IF EXISTS " + TABLE_ANTIDOT);
          // Create tables again
          onCreate(db);
      }   
  
  
      public ArrayList&lt;HashMap&lt;String,Object&gt;&gt; getAllAntidots() {
          ArrayList&lt;HashMap&lt;String,Object&gt;&gt; antidotList = new ArrayList&lt;HashMap&lt;String,Object&gt;&gt;();
          String selectQuery = "SELECT  * FROM " + TABLE_ANTIDOT + " ORDER BY " + KEY_TOX;
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(selectQuery, null);
          HashMap&lt;String , Object&gt; antidot;
          if (cursor.moveToFirst()) {
              do {
                  antidot = new HashMap&lt;String, Object&gt;();
                  antidot.put("sql_id", Integer.parseInt(cursor.getString(0)));
                  antidot.put("toxin", cursor.getString(1));
                  antidot.put("antidot", cursor.getString(2));
                  antidotList.add(antidot);
              } while (cursor.moveToNext());
          }
          return antidotList;
      }    
  }
  </code></pre>
  
  <p>antidotlist_layout.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      style="@style/mainView" 
      android:orientation="vertical" &gt;
      &lt;EditText android:id="@+id/EditText01"
          android:layout_height="wrap_content"
          android:layout_width="fill_parent"
          android:hint="Suchen"&gt;                               
      &lt;/EditText&gt;    
      &lt;ListView
          android:id="@android:id/list"
          style="@style/mainView" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;           
  &lt;/LinearLayout&gt;  
  </code></pre>
  
  <p>antidotlistitem_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      style="@style/mainView" 
      android:padding="5dip"&gt;
  
      &lt;!-- SQLite row id / hidden by default --&gt;
      &lt;TextView android:id="@+id/sqlite_id"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
          &lt;!-- android:visibility="gone" --&gt;
  
  
      &lt;!-- web site title --&gt;
      &lt;TextView
          android:id="@+id/tox_layout"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:paddingTop="8dip"
          android:paddingLeft="8dip"
          android:paddingBottom="4dip"
          android:textSize="18dip"
          android:textColor="#1a1a1a" /&gt;
  
      &lt;!-- web site url --&gt;
      &lt;TextView android:id="@+id/antidot_layout"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:paddingLeft="8dip"
          android:paddingBottom="6dip"
          android:textSize="15dip"
          android:textColor="#c00300"
          android:layout_below="@id/tox_layout"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I uploaded the files as eclipse workspace: <a href="http://www.file-upload.net/download-4447258/test.rar.html" rel="nofollow">http://www.file-upload.net/download-4447258/test.rar.html</a></p>