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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:42:52+00:00 2026-06-07T22:42:52+00:00

i have a listivew with custom arrayadapter and custom layout, it have a Checkbox.

  • 0

i have a listivew with custom arrayadapter and custom layout, it have a Checkbox.
I want to make this listview only one checkbox enabled but i dont know how can i do it.

This is my adapter, but the check and uncheck dont works fine. Any exmple please.

public class gremioAdapter extends ArrayAdapter<Gremio> {

Context context;
int layoutResourceId;
ArrayList<Gremio> data = null;
protected String comentarioAlEdiText;

public gremioAdapter(Context context, int layoutResourceId, ArrayList<Gremio> data)
{
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}

public void updateDataSet(Gremio objetoGremioAnadir) {
    this.data.add(objetoGremioAnadir);
    notifyDataSetChanged();

}

public void updateDataSet(Gremio objetoGremioAnadir, int posicion) {
    this.data.add(posicion, objetoGremioAnadir);
    notifyDataSetChanged();

}

public void updateDataSet(String comentario, int posicion) {
    this.data.get(posicion).comentario = comentario;
    notifyDataSetChanged();

}
public void updateDataSet() {

    notifyDataSetChanged();

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View row = convertView;
    GremioHolder holder = null;
    final GremioHolder h2 = holder;


    if (row == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new GremioHolder();
        holder.tvGremio = (TextView) row.findViewById(R.id.tvGremio);
        holder.cbActivo = (CheckBox) row.findViewById(R.id.cbGremioActivo);
        holder.tvComentario = (TextView) row.findViewById(R.id.tvComentario);

        row.setTag(holder);
    }
    else {
        holder = (GremioHolder) row.getTag();
    }

    Gremio gremioFinal = data.get(position);

    holder.tvGremio.setText(gremioFinal.literal);
    holder.tvComentario.setText(gremioFinal.comentario);

    if (data.get(position).getActivo().equals("1")) {
        holder.cbActivo.setChecked(true);
    }
    else {
        holder.cbActivo.setChecked(false);
    }

    holder.cbActivo.setOnClickListener(new OnClickListener()
    {


        @Override
        public void onClick(View v) {
            if (data.get(position).activo.equals("0"))
                h2.cbActivo.setChecked(true);
            if (data.get(position).activo.equals("1"))
                h2.cbActivo.setChecked(false);

        }
    });
    holder.cbActivo.setOnCheckedChangeListener(new OnCheckedChangeListener()
    {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (!isChecked) {
                    for (int i = 0; i < data.size(); i++) {
                        data.get(i).activo = "0";
                    }
                    data.get(position).activo = "1";
                }
                if (isChecked) {
                    for (int i = 0; i < data.size(); i++) {
                        data.get(i).activo = "0";
                    }
                }

                notifyDataSetChanged();

            }
        });

        return row;
    }

    public class GremioHolder {
        TextView tvGremio;
        CheckBox cbActivo;
        TextView tvComentario;
    }
}

}
  • 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-06-07T22:42:54+00:00Added an answer on June 7, 2026 at 10:42 pm

    This should take care of your requirement. A very good tutorial on how you can achieve this.

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

    So the basic funda is that,

    1. Extend a Layout (Linear/Relative) and implement the checkable interface.
    2. After inflating the layout, find out which child was selected and check the corresponding checkbox. Uncheck any other previously checked item.
    3. Make sure that your ListView’s XML has the following marked [android:choiceMode=”singleChoice”]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listView with custom objects defined by the xml-layout below. I want
I have 2 custom ListView Created as item layout + ArrayAdapter + My own
I want to have a listview with a custom adatper, extends ArrayAdapter, where Type
I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have used ListView and bounded my custom ArrayAdapter to it. Have setOnItemClickListener(...) bound
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a listview connected to a custom array adapter. This list shows information
I have a custom listview, i successfully parse the data into a list but
I have a ListView that I want to use with an ArrayAdapter to add
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.