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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:44:38+00:00 2026-06-12T15:44:38+00:00

I have my Box adapter that extends BaseAdapter public class BoxAdapter extends BaseAdapter {

  • 0

I have my Box adapter that extends BaseAdapter

public class BoxAdapter extends BaseAdapter {
  Context ctx;
  LayoutInflater lInflater;
  ArrayList<Product> objects;
  CheckBox cbBuy;

  BoxAdapter(Context context, ArrayList<Product> products) {
    ctx = context;
    objects = products;
    lInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }   
      @Override
      public int getCount() {
        return objects.size();
      }

      @Override
      public Object getItem(int position) {
        return objects.get(position);
      }

      @Override
      public long getItemId(int position) {
        return position;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        // используем созданные, но не используемые view
        View view = convertView;
        if (view == null) {
          view = lInflater.inflate(R.layout.childitem, parent, false);
        }

    Product p = getProduct(position);

    ((TextView) view.findViewById(R.id.tvDescr)).setText(p.name);
    ((TextView) view.findViewById(R.id.tvPrice)).setText(p.price + "");
    ((ImageView) view.findViewById(R.id.ivImage)).setImageResource(p.image);

    cbBuy = (CheckBox) view.findViewById(R.id.cbBox);

    cbBuy.setOnCheckedChangeListener(myCheckChangList);

    cbBuy.setTag(position);

    cbBuy.setChecked(p.box);
    return view;
  }

  Product getProduct(int position) {
    return ((Product) getItem(position));
  }

  ArrayList<Product> getBox() {
    ArrayList<Product> box = new ArrayList<Product>();
    for (Product p : objects) {
      // если в корзине
      if (p.box)
        box.add(p);
    }
    return box;
  }

  OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

      getProduct((Integer) buttonView.getTag()).box = isChecked;
    }
  };
}

now in the MainActivity I have to find out what checkbox was checked and remove it.

How can I do it. What method to invoke to getItemId position and how. Thank you in advance.

case R.id.delete:

 if (boxAdapter.cbBuy.isChecked()) {

   products.remove( checked position id );
  }
  • 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-12T15:44:39+00:00Added an answer on June 12, 2026 at 3:44 pm

    Just create method getBoxProducts in your adapter:

        public void removeBoxProducts()
        {
            List<Product> trash = new ArrayList<Product>();
            for (Product product:objects)
            {
                if (product.box)
                {
                    trash.add(product);
                }
            }
            for (Product product:trash)
            {
                objects.remove(product);
            }
        }
    

    To access this method use following:

    ListView list = (ListView) findViewByIf(R.id.list_view_id);
    BoxAdapter adapter = (BoxAdapter)list.getAdapter();
    adapter.removeBoxProducts();
    adapter.notifyDataSetChanged();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn html and jquery. My issue is that I have box
I have a box of selectors all sharing the class. widgetContainer can hold 3
I currently have a simple list view adapter that holds two rows of text.
I have a form with a text box and button, such that when the
I have an EditText component that searches a list using a custom adapter. It
I have a 1-Wire USB adapter (that bluish one) and wanted to use it
I have a list view whose adapter is in a different class in a
So im using an ExpandableListView and a custom adapter that extends BaseExpandableListViewAdapter in my
I have Windows box and I wish to invoke a .sh script on a
I have a box, when I click on it, I want the box animate

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.