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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:27:11+00:00 2026-06-15T10:27:11+00:00

I already spent a lot of time trying to solve this problem, I’ve seen

  • 0

I already spent a lot of time trying to solve this problem, I’ve seen a lot other StackOverflow Posts about this topic but I couldn’t find a solution that worked for me.

I have a ListActivity and a custom ArrayAdapter. There are several buttons in my listview for example a delete button. However the onItemClick method would only be invoked if the TextView of the list is clicked. I can add OnClickListeners to the buttons, but then I have the problem that I don’t know the position of the element to which the button belongs. I know I could set tags for every single button, but there has to be a better way of doing it!

This is my adapter:

    private class ItemListAdapter extends ArrayAdapter<Item> {
    private ArrayList<Item> items;
    private int countItems = 0;

    public ItemListAdapter(Context ctx, int textViewResourceId, ArrayList<Item> itemList){
        super(ctx, textViewResourceId, itemList);
        this.items = itemList;  
        this.countItems = itemList.size();
    }

    public int getCount(){
        return countItems;
    }

    public Item getItem(int pos){
        return itemList.get(pos);
    }

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

        //Get the current list item
        final Item currentItem = itemList.get(position);

        if (row == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = vi.inflate(R.layout.itemlist_item_row, null);
        }
        Item item = items.get(position);
        if (item != null){
            TextView bt = (TextView) row.findViewById(R.id.bt_itemlist_item);
            if (bt != null){
                bt.setText(item.getName());
            }
        }
        return row;
    }

}

Would be great if someone could tell me the best solution for this.

  • 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-15T10:27:12+00:00Added an answer on June 15, 2026 at 10:27 am

    Set the OnClickListeners for Buttons in getView() and you’ll get the position

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

Sidebar

Related Questions

I have a problem with php header redirect. I already spent hours trying to
I've looked through the various questions already asked on this topic, and I've spent
I have already spent a lot of time on Google, but have not found
I've spent a lot of time on this and it's clearly beyond my newbie
I've spent a lot of time and my head is blowing up already so
I've spent a whole day on this already without figuring it out. I'm hoping
I spent a lot of time, to add additional parameters to the Jquery-Autocomplete-Source. But
I believe I've looked everywhere possible and already feel to silly because I spent
I get this: Warning: session_start(): Cannot send session cookie - headers already sent by
This app already exists in the Apple App store and Android markets. It is

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.