Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:02:12+00:00 2026-05-28T02:02:12+00:00

I have a custom listview which display an image, textview and radio button. I

  • 0

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.

The problem goes here

  1. Lets assume that in the listview i selected the first radio button.
  2. 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.
  3. Here the filterd item in the first positon is also getting checked (because it was selected before)

Is it require to save the state of radio button before filtering ?

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<Contact> filteredItems = new ArrayList<Contact>();
                final ArrayList<Contact> localItems = new ArrayList<Contact>();
                localItems.addAll(originalContacts);
                final int count = localItems.size();
                for ( int i=0; i<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<Contact> localItems = (ArrayList<Contact>)results.values;
            notifyDataSetChanged();
            clear();
            for( Iterator<Contact> iterator = localItems.iterator(); iterator.hasNext();) {
                Contact index = (Contact) iterator.next();
                add(index);
            }

        } // end of syncronized

    }

}

Contact type class

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;
}

}

And i implemented LinearLayout checkable method as follows

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 < 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);
         }

}}

Any help is greatly appreciated..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:02:13+00:00Added an answer on May 28, 2026 at 2:02 am

    You must be trying to make radiobutton checked by using position parameter of the getView() method of your adapter. Instead try to set radiobutton checked based on some Id.

    EDIT:

    From your code study, I came to know that you have implemented this example:

    http://tokudu.com/2010/android-checkable-linear-layout/

    and as I had assumed earlier, the radio button check state is dependent on position of the row in listview but not actual item in the listview whose position is meant to be changed on filter.
    I have done couple of changes in your code and now the listview item check is not based on position of the item, but item itself(by matching the name of contact).

    Changes in the code are as follows:

    HelloListViewActivity:

    lv.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView<?> av, View view, int position,
                        long id) {
                    o = av.getItemAtPosition(position);
                    String name = ((Contact) o).name;
                    selectedName = name;
    

    ContactAdapter :

    static boolean isContactChecked = false;
    public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            final Contact contact = getItem(position);
            if(contact.name.equalsIgnoreCase(HelloListViewActivity.selectedName))
                isContactChecked = true;
            else
                isContactChecked= false;
    

    CheckableLinearLayout :

    @Override
        public void setChecked(boolean checked) {
            if (rb != null) {
                //  rb.setChecked(checked);
                rb.setChecked(ContactAdapter.isContactChecked);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one listview.which contain one image ,text and one button .i had creted
I have one custom ListView which contains one ImageView and one TextView, and I
I have a custom listview in which one textview and one checked box is
I have one custom ListView called AreasListView which I've included in the XML file.
I have a custom listview which changes size when one of the rows is
I have a ListView which uses a custom adapter to display rows of data.
Basically, I have a custom ListView in which each item looks like: <LinearLayout> <Table>
I have two ItemsControls, one a ListView, and one a custom control I am
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have an activity with a ListView which is populated through a custom ArrayAdapter.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.