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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:36:36+00:00 2026-05-27T13:36:36+00:00

I hope I get an answer to my question this time, I already posted

  • 0

I hope I get an answer to my question this time, I already posted a question on this but I guess people overlooked it since it was not put properly, here is a link to my previous question How do I know the ID's of views if I am inflating a view multiple times in the same parent on button click?
I am inflating child.xml which contains a TableLayout with 3 LinearLayouts which again contain TextView’s in my main Activity on button click event, the user can add as many views as he wants.

But I am confused as of how to collect the data from those textviews or setOnClickListeners to them since different views share the TextView’s which same Id.

People suggested me to use findViewById on the inflated view by appending it with appropriate type and store the reference in a List, but I am able to set an OnClickListener only for the first view that is inflated.

I wanted to know if it is even possible to achieve what I am doing? In an other post I read that findViewById finds the first possible instance of the view it can find. Is that a problem in my case.

Please have a look at my code snippet

TextView[] tv=new TextView[l.size()]; 
for(int i=0;i<tv.length;i++){ 
tv[i]=(TextView)l.get(i).findViewById(R.id.mdsnew_type_sp); 
tv[i].setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
showDialog(DATE_DIALOG_ID); } 
});
 //I have also tried this
 public void getData(){ 
 for(int i=0;i<l.size();i++){ 
 tv1=(TextView)l.get(i).findViewById(R.id.mdsnew_type_sp);
  }

But I am able to setOnClick Listener only for the first TextView and the rest are all ignored.

Here is another link that explains how I inflate my activity and a similar scenario but getting the information is not explained there Inflating a view multiple times in the same parent when a button is clicked

Any help will be rewarded, thanks in advance.

  • 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-27T13:36:37+00:00Added an answer on May 27, 2026 at 1:36 pm

    Since these TextViews have been added to a parent ViewGroup (in your case, a LinearLayout), you can traverse the parent’s list of child views, and add an OnClickListener to each one:

    for (int childPos = 0; childPos < myLayout.getChildCount(); childPos++) {
        myLayout.getChildAt(childPos).setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View v) { 
                // ...
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

unfortunately this question may get closed but i hope some people answer it. I
I'm not sure this question is appropriate here but I hope I could get
This question may have been asked already - but unfortunately, I could not find
Hope to get solution to this problem. I have been stuck on it since
Ok, I hope this question makes some sense but what is the difference between
I hope someone can answer this question. How does the UuidCreateSequential method in the
Unfortunately, the answer to this question isn't quite as simple as it sounds... but
since my title is buzzword compliant I hope I will get lots of answers
hope to get some help here because this is something that really makes me
EDIT: I've tagged this C in a hope to get more response. It's more

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.