title: autocomplete search with custom list
body: <p>I am creating a custom list view which has a autocomplete textview, the list is being populated from JSON.I want to filter the custom list by implementing the Filterable interface.Can anyone help me, how to implement the <code>getFilter()</code> method for custom list</p>
  
  <p>This is the <code>onCreate</code> method </p>
  
  <pre><code> @Override
   protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.custom_list);
      CustomListView = this;
  
      setListData(); //to set the list data
  
      Resources res = getResources();
      list = (ListView) findViewById(R.id.list);
  
      adapter = new CustomAdapter(CustomListView, CustomListViewValuesArr,
              res);
      list.setAdapter(adapter);
      list.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
              i1 = new Intent(CustomListHospital.this, Details.class);
              i1.putExtra("Name", list.getItemAtPosition(position).toString());
              startActivity(i1);
          }
      });
      inputSearch.addTextChangedListener(new TextWatcher() {
  
          @Override
          public void onTextChanged(CharSequence cs, int arg1, int arg2,
                  int arg3) {
  
              // When user changed the Text
              // getfilter to filter the search while user types in the search
              // box
  
  
              CustomListHospital.this.adapter.getFilter().filter(cs);
  
          }
  </code></pre>
  
  <p>This is the <code>setListData()</code> method        </p>
  
  <pre><code>   public void setListData() {
      i1 = getIntent();
      s1 = i1.getStringExtra("Speciality");
      try {
          InputStream inputStream = getAssets().open("Hospital_Json.txt");
          BufferedReader bufferedReader = new BufferedReader(
                  new InputStreamReader(inputStream));
          String tempString;
          StringBuilder builder = new StringBuilder();
  
          while ((tempString = bufferedReader.readLine()) != null) {
              builder.append(tempString);
  
              builder.append(System.getProperty("line.separator"));
          }
  
          jsonString = builder.toString();
  
          JSONObject jsonObject = new JSONObject(jsonString);
          JSONArray jsonArray = jsonObject.getJSONArray("data");
  
          for (int i = 0; i &lt; jsonArray.length(); i++) {
              JSONObject countryObject = jsonArray.getJSONObject(i);
              String cellNo = countryObject.getString("Telephone");
              String name = countryObject.getString("Name");
              String special = countryObject.getString("Speciality");
              String category = countryObject.getString("Category");
  
              ListModel sched = new ListModel();
  
              if (category.equals("Doctor") &amp;&amp; special.equals(s1)) {
                  sched.setHospitalName(name);
                  sched.setCellNo(cellNo);
                  CustomListViewValuesArr.add(sched);
              } else if (category.equals("Hospital") &amp;&amp; special.equals(s1)) {
                  sched.setHospitalName(name);
                  sched.setCellNo(cellNo);
                  CustomListViewValuesArr.add(sched);
              }
          }
  
      } catch (IOException e) {
          e.printStackTrace();
      } catch (JSONException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>This is code to the custom adapter I have created</p>
  
  <pre><code>   public class CustomAdapter extends BaseAdapter implements OnClickListener,Filterable {
  
  private Activity activity;
  private ArrayList data;
  private static LayoutInflater inflater = null;
  public Resources res;
  ListModel tempValues = null;
  int i = 0;
  
  public CustomAdapter(Activity a, ArrayList d, Resources resLocal) {
  
      activity = a;
      data = d;
      res = resLocal;
  
      inflater = (LayoutInflater) activity
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
  }
  
  public int getCount() {
  
      if (data.size() &lt;= 0)
          return 1;
      return data.size();
  }
  
  public Object getItem(int position) {
      return position;
  }
  
  public long getItemId(int position) {
      return position;
  }
  
  public static class ViewHolder {
  
      public TextView text;
      public TextView text1;
      public TextView textWide;
  
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
  
      View vi = convertView;
      ViewHolder holder;
      Intent i1 = new Intent();
  
      if (convertView == null) {
  
          vi = inflater.inflate(R.layout.row_item, null);
  
          holder = new ViewHolder();
          holder.text = (TextView) vi.findViewById(R.id.text);
          holder.text1 = (TextView) vi.findViewById(R.id.text1);
  
          vi.setTag(holder);
      } else
          holder = (ViewHolder) vi.getTag();
  
      if (data.size() &lt;= 0) {
          holder.text.setText("No Data");
  
      } else {
  
          tempValues = null;
          tempValues = (ListModel) data.get(position);
  
          holder.text.setText("Name: " + tempValues.getHospitalName());
          holder.text1.setText("Phone No: " + tempValues.getCellNo());
  
          vi.setOnClickListener(new OnItemClickListener(position));
      }
      return vi;
  }
  
  @Override
  public void onClick(View v) {
      Log.v("CustomAdapter", "Row button clicked");
  }
  
  private class OnItemClickListener implements OnClickListener {
      private int mPosition;
  
      OnItemClickListener(int position) {
          mPosition = position;
      }
  
      @Override
      public void onClick(View arg0) {
  
          CustomListHospital sct = (CustomListHospital) activity;
  
      }
  }
  
  @Override
  public Filter getFilter() {
      // TODO Auto-generated method stub
      return null;
  }
  
  }
  </code></pre>