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 7030031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:00+00:00 2026-05-28T00:37:00+00:00

hi i am creating a custom listview with two chekboxes and problen is when

  • 0

hi i am creating a custom listview with two chekboxes and problen is when i check a checkbox and scroll down another checkbox adjacent to the checked one also get checked i want to know why it is happening what should i do to avoid that error this is my code

public class ListTestActivity extends ListActivity {
/** Called when the activity is first created. */
String tag = "Events";
String[] presidents;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 // Create an array of Strings, that will be put to our ListActivity
    presidents =getResources().getStringArray(R.array.pres_array);

        ArrayAdapter<Model> adapter = new InteractiveArrayAdapter(this,
                getModel());
        Log.d(tag," event");
        setListAdapter(adapter);
        Log.d(tag," 1");
    }

    private List<Model> getModel() {
        Log.d(tag,"bht");
        int index = presidents.length;
        int positio;
        String Linux;
        //List<Model> list = new ArrayList<Model>();
        /*for(positio=0;positio<=index ;++positio){
            String Linux="hai";
            List<Model> list = new ArrayList<Model>();
            list.add(get(presidents[positio]));
            list.add(get(Linux));
            Log.d(tag," 2");
                     //if(positio>=10){
            return list;

            //}
        }*/
        List<Model> list = new ArrayList<Model>();
        //int position=0;
        //List<Model> list = new ArrayList<Model>();
        //list.add(get(presidents[position]));
        for(positio=0;positio<index ;positio++){
            Linux=presidents[positio];
            list.add(get(Linux));
        }

        Log.d(tag,"bht1");
        /*list.add(get("Windows7"));
        list.add(get("Suse"));
        list.add(get("Eclipse"));
        list.add(get("Ubuntu"));
        list.add(get("Solaris"));
        list.add(get("Android"));
        list.add(get("iPhone"));*/
        // Initially select one of the items
        //list.get(1).setSelected(true);
        //String re=list.get(1);
        Log.d(tag," event1");
        return list;

    }private Model get(String s) {
        Log.d(tag," event2");
        return new Model(s);
}}


public class InteractiveArrayAdapter extends ArrayAdapter<Model> {
String tag = "Events";
private final List<Model> list;
private final Activity context;

public InteractiveArrayAdapter(Activity context, List<Model> list) {
    super(context, R.layout.rowbuttonlayout, list);
    this.context = context;
    this.list = list;
}

static class ViewHolder {
    protected TextView text;
    protected CheckBox checkbox,checkbox1;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Log.d(tag," 3");
    View view = null;
    if (convertView == null) {
        LayoutInflater inflator = context.getLayoutInflater();
        view = inflator.inflate(R.layout.rowbuttonlayout, null);
        final ViewHolder viewHolder = new ViewHolder();
        viewHolder.text = (TextView) view.findViewById(R.id.label);
        viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
        viewHolder.checkbox1 = (CheckBox) view.findViewById(R.id.checkbox1);
        viewHolder.checkbox
                .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

Model element = (Model)viewHolder.checkbox.getTag();
    String posit=element.getName();
Log.d(posit,"identifyme");
element.setSelected(buttonView.isChecked());
                        int dam=viewHolder.checkbox.getId();
                        //Log.d(dam,"bbb");
                        System.out.println("Checked : " + viewHolder.checkbox.getId());

                    }
                });
        viewHolder.checkbox1
        .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {

Model element = (Model) viewHolder.checkbox1.getTag();

    String posit=element.getName();

                Log.d(posit,"identify");
                element.setSelected(buttonView.isChecked());



                //Log.d(tag,"identifyme");
            }
        });

        view.setTag(viewHolder);
        Log.d(tag,"me");
        viewHolder.checkbox.setTag(list.get(position));
        viewHolder.checkbox1.setTag(list.get(position));
    } else {
        view = convertView;
        Log.d(tag,"meeee");
        ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
        ((ViewHolder) view.getTag()).checkbox1.setTag(list.get(position));
    }
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.text.setText(list.get(position).getName());
    //String Dis=list.get(position).getName();
    //Log.d(Dis," event7");
    holder.checkbox.setChecked(list.get(position).isSelected());
    holder.checkbox1.setChecked(list.get(position).isSelected());
    Log.d(tag," event7");

    return view;

}
}

public class Model {
String tag = "Events";
private String name;
private boolean selected;

public Model(String name) {
    this.name = name;
    selected = false;
    Log.d(tag," ev");
}

public String getName() {
    Log.d(tag," eve");
    return name;
}

public void setName(String name) {
    Log.d(tag," nt");
    this.name = name;
}

public boolean isSelected() {
    Log.d(tag," t");
    return selected;
}

public void setSelected(boolean selected) {
    Log.d(tag," eventer");
    this.selected = selected;
}

}
  • 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-28T00:37:01+00:00Added an answer on May 28, 2026 at 12:37 am

    This link also has the same problem and it is resolved in the following link.

    Storing the state of checkbox in listview while using custom BaseAdapter in android?

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating custom cell in my iphone aap and I am also adding
I am creating custom membership provider for my asp.net application. I have also created
I've come across two recommendations for creating custom html helpers: either extend an existing
I know of two ways of creating custom JSF components: 1. Native JSF way:
I currently have a custom listview with two rows of text in each item,
Hi i am creating a custom listview with texview ,imageview and i am accessing
After creating a custom Dialog using a ListView and my own implementation of ListAdapter
I am creating a custom listview. The data is not coming from a cursor
I am creating a ListView dynamically and want to add two TextViews in a
everybody i am creating a custom listview with dynamic radiobuttons adding to radiogroup upto

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.