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

  • Home
  • SEARCH
  • 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 9306243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:07:44+00:00 2026-06-19T00:07:44+00:00

I have listview which contains textview and buttons. When i delete listview item and

  • 0

I have listview which contains textview and buttons. When i delete listview item and i try to scroll down, i get exception on this:

BuildQueue eile = countryList.get(position);

Exception:

02-08 19:11:04.279: E/AndroidRuntime(10509): java.lang.IndexOutOfBoundsException: Invalid index 15, size is 15

Seems i do not updating something when i delete item from listview. I think i have problem with ViewHolder, but i do not know what kind of…

My ArrayAdapter code:

public class MyCustomAdapter extends ArrayAdapter<BuildQueue> {

        private ArrayList<BuildQueue> countryList;

        public MyCustomAdapter(Context context, int textViewResourceId,ArrayList<BuildQueue> countryList) {
            super(context, textViewResourceId, countryList);
            this.countryList = new ArrayList<BuildQueue>();
            this.countryList.addAll(countryList);
        }

        private class ViewHolder {
            TextView code;
            TextView field;
            Button del;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewHolder holder = null;

            if (convertView == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = vi.inflate(R.layout.queue_buildings, null);

                holder = new ViewHolder();
                holder.code = (TextView) convertView.findViewById(R.id.code);
                holder.field = (TextView) convertView.findViewById(R.id.field_text);
                holder.del = (Button) convertView.findViewById(R.id.del_button);
                convertView.setTag(holder);

                holder.del.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        Button del_button = (Button) v;
                        BuildQueue building = (BuildQueue) del_button.getTag();
                        countryList.remove(building);
                        dataAdapter.notifyDataSetChanged();
                    }
                });
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            BuildQueue eile = countryList.get(position);
            holder.code.setText(" ( Level: " + eile.getOld_level() + " to "+eile.getNew_level()+")");

            holder.field.setText(eile.getNameSort());
            holder.field.setTag(eile);

            holder.del.setText("Delete");
            holder.del.setTag(eile);

            return convertView;

        }
    }
  • 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-19T00:07:45+00:00Added an answer on June 19, 2026 at 12:07 am

    You are using a two arrays in your Adapter, but only changing one of them.

    Every Adapter uses getCount() to determine how many row should be drawn. ArrayAdapter’s getCount() simply asks for the size of the array that you pass to the super constructor here: super(context, textViewResourceId, countryList);. But you are also using a second, local array and when you delete a value from this countryList getCount() has no idea this happened which results in getView() throwing an IndexOutOfBoundsException…

    Either extend BaseAdapter, or use ArrrayAdapter’s methods like getItem(), add(), and remove() and remove your local data set.

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

Sidebar

Related Questions

I have a ListView which contains custom rows. This custom row has following UI
I have a listview which contains some textview and imageview. i have a horizontal
I have ListView, which contains a TextView and a CheckBox. Now I am able
I have a ListView in which each item has a complex layout that contains,
I have a listview which contains 2 Textview. one textview is shown inside a
I have a custom ListView which contains one TextView (Of numbers) and one EditText
I have one custom ListView which contains one ImageView and one TextView, and I
I have a custom listview adapter which contains two buttons, the problem is it's
I have a ListView which contains an ImageView and a TextView. I'm subclassing ArrayAdapter
I have a ListView which contains some texts and pic for each item (it's

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.