title: Radiobutton state updation after filtering in custom listview
body: <p>I have a custom listview which display an image, textview and radio button. I need to select only one item (i.e RadioButton)at a time. I attached a textwatcher to this listview and everything working fine.</p>
  
  <p>The problem goes here</p>
  
  <ol>
  <li>Lets assume that in the listview i selected the first radio button.</li>
  <li>I performed search option in EditText box show that it filters the listview items and
  the filtered list item/items will be displayed at the first position.</li>
  <li>Here the filterd item in the first positon is also getting checked (because it was selected    before)</li>
  </ol>
  
  <p>Is it require to save the state of radio button before filtering ?</p>
  
  <pre><code>public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      if ( row == null) {
      //  Log.d(tag,"Starting XML Row Inflation");
          LayoutInflater inflater = (LayoutInflater) this.getContext()
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          row = inflater.inflate(R.layout.custom_row_view_user, parent, false);
          Log.d(tag,"Successfully completed XML Row Inflation for positon"+position); 
  
      }
  
      // Get item
      final Contact contact = getItem(position);
      contactIcon = (ImageView) row.findViewById(R.id.image_icon);
      name = (TextView) row.findViewById(R.id.textviewname);
      name.setText(contact.name);
  
              rb = (RadioButton) row.findViewById(R.id.radiobutton1);
              rb.setEnabled(true);
  
      String imgFilePath = DIR + contact.imageId;
      try {
  
          Bitmap bitmap = BitmapFactory.decodeStream(this.context.getResources().getAssets().open(imgFilePath));
          contactIcon.setImageBitmap(bitmap);
      } catch(IOException e) {
          e.printStackTrace();
      }
  
      return row; 
  
  }
  
  
  // Filter function
  @Override
  public Filter getFilter() {
      if (filter == null) {
          filter = new ContactFilter();
      }
      return filter;
  }
  
  private class ContactFilter extends Filter {
  
      @Override
      protected FilterResults performFiltering(CharSequence prefix) {
          FilterResults results = new FilterResults();
          if( prefix == null || prefix.length() == 0) {
              synchronized (this) {
                  results.values = originalContacts;
                  results.count = originalContacts.size();
              }
          } else {
              synchronized (this) {
                  String prefixString = prefix.toString().toLowerCase();
                  final ArrayList&lt;Contact&gt; filteredItems = new ArrayList&lt;Contact&gt;();
                  final ArrayList&lt;Contact&gt; localItems = new ArrayList&lt;Contact&gt;();
                  localItems.addAll(originalContacts);
                  final int count = localItems.size();
                  for ( int i=0; i&lt;count; i++) {
                      final Contact contact = localItems.get(i);
                      final String contactName = contact.name.toString().toLowerCase();
                      if ( contactName.startsWith(prefixString) ) {
                          filteredItems.add(contact);
  
                      } else {
  
                      }
  
  
                  }
                  results.values = filteredItems;
                  results.count = filteredItems.size();
              } // end of synchronized.
          }
  
          return results;
      }
  
      @Override
      protected void publishResults(CharSequence prefix,
              FilterResults results) {
          synchronized (this) {
  
              @SuppressWarnings("unchecked")
              final ArrayList&lt;Contact&gt; localItems = (ArrayList&lt;Contact&gt;)results.values;
              notifyDataSetChanged();
              clear();
              for( Iterator&lt;Contact&gt; iterator = localItems.iterator(); iterator.hasNext();) {
                  Contact index = (Contact) iterator.next();
                  add(index);
              }
  
          } // end of syncronized
  
      }
  
  }
  </code></pre>
  
  <p>Contact type class</p>
  
  <pre><code>public class Contact {
  public String name;
  public String imageId;
  public String type;
  public boolean isSelected;
  public boolean useDefaultKey;
  public boolean flag;
  
  public Contact() {
  
  }
  
  public Contact(String name, String type, String resouceFilePath) {
      this.name = name;
      this.type = type;
      this.imageId = resouceFilePath;
      this.isSelected = false;
      this.useDefaultKey = true;
      this.flag = false;
  
  }
  
  @Override
  public String toString() {
      return this.name;
  }
  
  public boolean getCheckeBoxStatus() {
      return isSelected;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And i implemented LinearLayout checkable method as follows</p>
  
  <pre><code>public class CheckableLinearLayout extends LinearLayout implements Checkable{
  
  
  private RadioButton rb;
  public CheckableLinearLayout(Context context, AttributeSet attrs) {
      super(context, attrs);
      // TODO Auto-generated constructor stub
  }
  
  
  
  @Override
  protected void onFinishInflate() {
   super.onFinishInflate();
   // find checked text view
   int childCount = getChildCount();
   for (int i = 0; i &lt; childCount; ++i) {
       View v = getChildAt(i);
       if (v instanceof RadioButton) {
           rb = (RadioButton)v;
       }
   }
  }
  @Override
  public boolean isChecked() {
       return rb != null ? rb.isChecked() : false; 
  }
  
  @Override
  public void setChecked(boolean checked) {
  
  
      if (rb != null) {
      //  Toast.makeText(getContext(), "Clicked radio buttton", Toast.LENGTH_LONG).show();
           rb.setChecked(checked);
  
           }
  }
  
  @Override
  public void toggle() {
      if (rb != null) {
           rb.toggle();
           rb.setChecked(false);
           }
  
  }}
  </code></pre>
  
  <p>Any help is greatly appreciated..</p>