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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:39:08+00:00 2026-05-27T15:39:08+00:00

I have a listview with each row containing some text and a delete button.

  • 0

I have a listview with each row containing some text and a delete button.
When delete button is pressed the row has to be deleted.

I am using a base adapter and there is a global list the item of which will be displayed.

Please see my adpater code below

    public class JobCartListAdapter extends BaseAdapter {

    protected LayoutInflater mInflater;
    public JobCartListAdapter( Context mContext) {
        super();

        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
    }

    Context mContext;
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return JobsManager.JobsCartList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.job_cart_row, null);
            holder = new ViewHolder();
            holder.text1 = (TextView) convertView.findViewById(R.id.title);
            holder.delete = (ImageButton)convertView.findViewById(R.id.delete);
            holder.delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i("Remove from" , "" + position);
                    JobsManager.JobsCartList.remove(position)   ;
                    notifyDataSetChanged();
                }
            });
            convertView.setTag(holder);
        } else {

            holder = (ViewHolder) convertView.getTag();
        }

        holder.text1.setText(JobsManager.JobsCartList.get(position).getTitle());
        return convertView;
    }

    static class ViewHolder {
        TextView text1;
        ImageButton delete;
    }
}

the issue i am facing is :

  1. when i press delet for the firstime , the position within the list is correct and the item is deleted and list is getting refreshed

  2. when i click again on a row in the refreshed list , the corresponding position passed to getview is not right . So its leading to an index out of bound exception as that position is used as index for list . I checked my list and it is correctly updated on add and remove .
    Its the problem with list adapter. After refresh of the list with call of notifystatechanged, when a row is clicked, the postion of the row returned is not correct.

please help

  • 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-27T15:39:09+00:00Added an answer on May 27, 2026 at 3:39 pm

    You don’t have to remove the View just remove the relates object by adapter.remove(adapter.getItem(position));
    it will remove the specified object from list & call the the method notifyDatasetChanged()

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

Sidebar

Related Questions

I have a listView using a custom adapter. Each row contains a button and
I have a listView, where each row has a button in the row layout.
I have android application with ListView, where each row has own refresh button. Refreshing
I have a ListView with some text, each row contains different length text and
I have a ListView with some elements on it. Each row has a TextView
I have an app using a ListView as a main screen. Each row displays
I have a ListView on each row i have a LinearLayout with some objects
I have a list view with text and button in each row, list view
I have a ListView where each row has two webviews side by side, taking
I have a ListView and each row contains button. I don't want to assign

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.