title: Android search function on custom adapter list
body: <p>I'm pretty new to android. I'm trying to develop a search function on a list of items by using arrayadapter as shown below. The search function should perform the search on the model's name.</p>
  
  <pre><code>    public class InteractiveArrayAdapter extends ArrayAdapter&lt;Model&gt; implements Filterable{
  
            private final List&lt;Model&gt; list;
            private final Activity context;
            protected Filter filter;
            private ArrayList&lt;Model&gt; arraylist;
  
            public InteractiveArrayAdapter(Activity context, List&lt;Model&gt; list) {
              super(context, R.layout.mylist, list);
              this.context = context;
              this.list = list;
              this.arraylist = new ArrayList&lt;Model&gt;();
              this.arraylist.addAll(list);
              //filter = new PhysFilter();
            }
  
            class ViewHolder {
              protected TextView text;
              protected CheckBox checkbox;
              protected ImageView icon_verify, icon_auth;
            }
  
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
              View view = null;
              if (convertView == null) {
                LayoutInflater inflator = context.getLayoutInflater();
                view = inflator.inflate(R.layout.mylist, null);
                final ViewHolder viewHolder = new ViewHolder();
                viewHolder.text = (TextView) view.findViewById(R.id.label);
                Typeface face=Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
                viewHolder.text.setTypeface(face);
  
                viewHolder.icon_verify = (ImageView) view.findViewById(R.id.icon_verify);
                if(list_m.get(position).isVerified() == true)
                    viewHolder.icon_verify.setImageResource(R.drawable.verify_icon2);
                else
                    viewHolder.icon_verify.setImageResource(R.drawable.verify_icon);
                viewHolder.icon_auth = (ImageView) view.findViewById(R.id.icon_auth);
                if(list_m.get(position).isAuthorised() == true)
                    viewHolder.icon_auth.setImageResource(R.drawable.auth_icon2);
                else
                    viewHolder.icon_auth.setImageResource(R.drawable.auth_icon);
                viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
                viewHolder.checkbox
                    .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
                      @Override
                      public void onCheckedChanged(CompoundButton buttonView,
                          boolean isChecked) {
                        Model element = (Model) viewHolder.checkbox.getTag();
                        element.setSelected(buttonView.isChecked());
                        System.out.println("checked change");
  
                      }
                    });
                view.setTag(viewHolder);
                viewHolder.checkbox.setTag(list.get(position));
              } else {
                view = convertView;
                ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
              }
              ViewHolder holder = (ViewHolder) view.getTag();
              holder.text.setText(list.get(position).getName());
              holder.checkbox.setChecked(list.get(position).isSelected());
              return view;
            }
  
          // Filter Class
              public void filter(String charText) {
                  charText = charText.toLowerCase(Locale.getDefault());
                  list.clear();
                  if (charText.length() == 0) {
                      list.addAll(arraylist);
                  } else {
                      for (Model wp : arraylist) {
                          if (wp.getName().toLowerCase(Locale.getDefault())
                                  .contains(charText)) {
                              list.add(wp);
                          }
                      }
                  }
                  notifyDataSetChanged();
              }
  }
  </code></pre>
  
  <p>list.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="match_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;TextView
          android:id="@+id/label"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@+id/label"
          android:layout_marginLeft="70px"
          android:layout_marginTop="10px"
          android:textSize="22px" &gt;
          &lt;requestFocus /&gt;
      &lt;/TextView&gt;
  
      &lt;CheckBox
          android:id="@+id/check"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:textSize="0sp"
          android:focusable="false"
          android:layout_marginLeft="10dp"
          android:button="@layout/checkbox" /&gt;
  
      &lt;ImageView
          android:id="@+id/icon_verify"
          android:layout_width="30px"
          android:layout_height="30px"
          android:layout_marginLeft="600px"
          android:layout_marginRight="10px"
          android:layout_marginTop="30px" &gt;
      &lt;/ImageView&gt;
      &lt;ImageView
          android:id="@+id/icon_auth"
          android:layout_width="30px"
          android:layout_height="30px"
          android:layout_marginLeft="650px"
          android:layout_marginRight="5px"
          android:layout_marginTop="30px" &gt;
      &lt;/ImageView&gt;
  
  &lt;/RelativeLayout&gt; 
  </code></pre>
  
  <p>Model.java</p>
  
  <pre><code>public class Model {
      private int tradeID, pos;
      private String name;
      private boolean selected, verified, authorised;
  
      public Model(int pos, String name, int tradeID, boolean verified, boolean authorised){
          this.pos = pos;
          this.name = name;
          this.tradeID = tradeID;
          this.verified = verified;
          this.authorised = authorised;
          selected = false;
      }
  
      public int getPos() {
          return pos;
      }
      public void setPos(int pos) {
          this.pos = pos;
      }
      public int getTradeID() {
          return tradeID;
      }
  
      public void setTradeID(int tradeID) {
          this.tradeID = tradeID;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public boolean isSelected() {
          return selected;
      }
  
      public void setSelected(boolean selected) {
          this.selected = selected;
      }
  
      public boolean isVerified() {
          return verified;
      }
      public void setVerified(boolean verified) {
          this.verified = verified;
      }
      public boolean isAuthorised() {
          return authorised;
      }
      public void setAuthorised(boolean authorised) {
          this.authorised = authorised;
      }
  
  }
  </code></pre>
  
  <p>Below is currently what I did on the edittext, however when I typed in any characters the list display will be empty. Can anyone suggest what I should do or what I did wrong here? Any Help would be greatly appreciated. Thanks!</p>
  
  <pre><code>EditText search=(EditText)header.findViewById(R.id.searchbox);
  
  search.addTextChangedListener(new TextWatcher() {
          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
              // When user changed the Text
              String text = search.getText().toString().toLowerCase(Locale.getDefault());
                      ((InteractiveArrayAdapter) adapter).filter(text);
          }
  
          @Override
          public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                              int arg3) {
              // TODO Auto-generated method stub
          }
  
          @Override
          public void afterTextChanged(Editable arg0) {
              // TODO Auto-generated method stub                          
          }
  });
  </code></pre>