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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:23:39+00:00 2026-06-18T11:23:39+00:00

I have custom adapter with two textviews and one button, which should delete that

  • 0

I have custom adapter with two textviews and one button, which should delete that row.

public class ListViewAdapter extends ArrayAdapter<OneRowListView> implements OnClickListener {
private ArrayList<OneRowListView> items;
private ContactsActivity ca;
private int position;
private OneRowListView o;

public ListViewAdapter(Context context, int textViewResourceId, ArrayList<OneRowListView> items) {
    super(context, textViewResourceId, items);
    this.items = items;
    ca = (ContactsActivity) context;
}   
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
        View v = convertView;
        position = pos;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)ca.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.one_item_contacts_list, null);
        }
        o = items.get(position);
        if (o != null) {
                TextView name = (TextView) v.findViewById(R.id.name);
                TextView surname = (TextView) v.findViewById(R.id.surname);
                TextView phoneNumber = (TextView) v.findViewById(R.id.phonenumber);
                Button deleteButton = (Button) v.findViewById(R.id.deleteButton);
                deleteButton.setOnClickListener(this);
        // ...
        }
        return v;
 }

@Override
public void onClick(View v) {
    switch(v.getId()){
    case R.id.deleteButton:
        remove(items.remove(position));
        notifyDataSetChanged();
        break;
    }       
}
 }

problem is, when any button is pressed, it always removes last row, not the current one. Variable position always points at last row.
Where is the problem ?

  • 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-18T11:23:40+00:00Added an answer on June 18, 2026 at 11:23 am

    The problem is that when you do position = pos; you keep overriding the ‘position’ variable (since getView() gets called for each row while you are scrolling your ListView).

    As a quick fix, instead of using the ‘position’ variable, you could store in your deleteButton a tag that contains the row position. For example something like this, in your getView() method:

    deleteButton.setTag(pos);
    

    Then in your onClick() method you can do:

    int position = (int) v.getTag();
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one gridview and use custom adapter for that. I added two
I have created one gridview and use custom adapter for that. I added two
I have a custom adapter for my ListView which has multiple TextViews. I want
I have a custom listview adapter which contains two buttons, the problem is it's
I have a custom adapter that visualize each row in the list of Orders.
I have a listview with a custom adapter, the adapter contains two TextViews and
I have ListView with custom adapter extends ArrayAdapter. Each item is object: public class
Here's my aproach: I have a custom ListView containing a custom Adapter containing two
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
i have a ExpandableListActivity with an custom Adapter. if the custom row of the

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.