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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:29:36+00:00 2026-06-16T19:29:36+00:00

I have a ListView items/cell that has a few layers, relative, linearLayout etc. I

  • 0

I have a ListView items/cell that has a few layers, relative, linearLayout etc.
I tried doing v.getParent() inside the onClick of the button but it just went one layer up. How can I get a reference to the root of the current element inside onClick event handler?

Here is my getView()

             Button v = (Button)findViewById(R.id.myButton);

             v.setOnClickListener(new OnClickListener(){
                     onClick(View v) {

                        //Right here I want to find another view inside the cell.
                        View otherView = ???.findViewById(R.id.myOtherViewInListItem); 
                             otherView.setBackgroundColor(...);
                        .........................................
                     } 
              });
  • 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-16T19:29:37+00:00Added an answer on June 16, 2026 at 7:29 pm

    I’m imagining that this button is inside the ListView element. Based on this assumption:

    1. create only one OnClickListener. The way you’re doing you’re creating adapter.getCount() OnClick listener and waste memory like crazy.

    2. Maybe you want to completely remove the button and use the OnItemClick to track clicks on your whole ListView element, this will pass to you the reference to the whole View.

    3. If you really must have the button, inside your getView you store a reference to the parent, something like that:

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // do whatever you're doing to get the view, let's call it v
          Button b = (Button)v.findViewById(/* your button id */ )
          b.setTag(v)
      }
      

    then on your click listener you can:

        onClic(View v){
            View parent = (View)b.getTag();
        }
    

    and if that answer works for you (I know it does) accept it as correct like Daniel Martinus pointed out.

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

Sidebar

Related Questions

I have a listview with several items that are created dynamically, each has two
I have a ListView that shows around 300 items. When something is changed and
I have a ListView that I am populating with items from an ObservableCollection .
A have a ListView that is rendered with multiple items. Now I want to
I have an android listview filled with items. Every item has a button. This
I have a listview of items that have a listview as a child. My
I have a ListView that displays a bunch of homework assignments. The ListView items
How can I recreate listView? I have listView with items containing few TextViews and
I have a ListView that presents items horizontally. Each Item is a 1 column
I have a listview that can contain up to roughly 2,000 listview items I

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.