title: What is the mistake in setting filter for Listview
body: <p>I have a model class which holds different items like string and image URL.</p>
  
  <p>I have implemented a filter for this, but unfortunately all the items get disappear whenever i search. help me in how to implement the filter.</p>
  
  <p>Here is the source code.</p>
  
  <pre><code>package Dummy.list.filter;
  import android.app.Activity;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.widget.EditText;
  import android.widget.ListView;
  
  public class DummyListFilterActivity extends Activity {
      /** Called when the activity is first created. */
  
  
      myadapter adapter;
      EditText filterText;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
  
          ModelClass[] str = new ModelClass[]{new ModelClass("cell",R.drawable.ic_launcher,1), 
                  new ModelClass("Bus",R.drawable.ic_launcher,2),
                  new ModelClass("Car",R.drawable.ic_launcher,3),
                  new ModelClass("Van",R.drawable.ic_launcher,4),
                  new ModelClass("Lorry",R.drawable.ic_launcher,5)};
  
          ListView list = (ListView)findViewById(R.id.Service_name_list);
          filterText = (EditText)findViewById(R.id.txtUserName);
          filterText.addTextChangedListener(filterTextWatcher);
  
          list.setTextFilterEnabled(true);
  
          adapter = new myadapter(this, 0, str); 
  
         //ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,str);
  
          list.setAdapter(adapter);
  
      }
  
      private TextWatcher filterTextWatcher = new TextWatcher() {
  
          public void afterTextChanged(Editable s) {
          }
  
          public void beforeTextChanged(CharSequence s, int start, int count,
                  int after) {
          }
  
          public void onTextChanged(CharSequence s, int start, int before,
                  int count) {
              adapter.getFilter().filter(s.toString());
          }
  
      };
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          filterText.removeTextChangedListener(filterTextWatcher);
      }
  
  }
  </code></pre>
  
  <p>This is how my Adapter class looks</p>
  
  <pre><code>package Dummy.list.filter;
  import java.util.List;
  import android.app.Activity;
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  
      public class myadapter extends ArrayAdapter&lt;ModelClass&gt;
      {
  
          //private final List&lt;String&gt; contactNumbers;
              //private final String[] contactDetails;
              private final ModelClass[] contactDetails;
              private final Activity AdapterContext;
  
  
          public myadapter(Context context, int textViewResourceId,ModelClass[] objects) 
          {
              super(context, textViewResourceId, objects);
              // TODO Auto-generated constructor stub
              contactDetails = objects;
              AdapterContext = (Activity) context;
          }
  
          static class ViewHolder {
              protected TextView ContactNumbers;
              protected ImageView ContactImage;
          }
  
          public View getView(int position, View convertView, ViewGroup parent)
          {
              View view = null;
              if(convertView == null)
              {
                  LayoutInflater inflator = AdapterContext.getLayoutInflater();
                  view = inflator.inflate(R.layout.item, null);
  
                  final ViewHolder holder = new ViewHolder();
                  holder.ContactImage = (ImageView) view.findViewById(R.id.image);
                  holder.ContactNumbers = (TextView) view.findViewById(R.id.text);    
                  view.setTag(holder);
              }
              else
              {
                  view = convertView;
              }
  
              ViewHolder holder = (ViewHolder) view.getTag();
              holder.ContactNumbers.setText(contactDetails[position].getServiceName());
              holder.ContactImage.setImageResource(contactDetails[position].getServiceImage());
              view.setTag(holder);
              return view;
  
          }
  
      }
  </code></pre>