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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:55:26+00:00 2026-06-11T22:55:26+00:00

I am adding a child view to a Linear Layout. The child views itself

  • 0

I am adding a child view to a Linear Layout. The child views itself has some textview and imageviews in a Relativelayout.
The child view is added dynamically in the LinearLayout on clicking a button. Right now I am able to add the child view as shown in this pic.
http://dl.dropbox.com/u/50249620/SC20120926-031356.png
what I have to do is uniquely identify which child view has been clicked in order to show appropriate actions.
My code where I am adding the child view.

addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);


                customView1 = inflater.inflate(R.layout.people, null);

                peopleName = (TextView) customView1.findViewById(R.id.peopleName);

                peopleName.setText(autoComplete.getText());
                customView1.setId(peopleInvitedRelativeLayout.getChildCount() + 1);

                params4 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

                customView1.setLayoutParams(params4);
                peopleInvitedRelativeLayout.addView(customView1, params4);              

            }
        }); 

Any help or suggestions would be appreciated. Thanks.

  • 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-11T22:55:27+00:00Added an answer on June 11, 2026 at 10:55 pm

    You can add a custom tag to any view simply by doing the following when you create the view

    view.setTag(Object o);
    

    then later in the onClickListener find the tag with

    view.getTag()
    

    setTag(Object o) will accept any kind of object be it a string, int or custom class

    EDIT

    addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
    
                customView1 = inflater.inflate(R.layout.people, null);
    
                peopleName = (TextView) customView1.findViewById(R.id.peopleName);
    
                peopleName.setText(autoComplete.getText());
                customView1.setId(peopleInvitedRelativeLayout.getChildCount() + 1);
    
                params4 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    
                customView1.setLayoutParams(params4);
                peopleInvitedRelativeLayout.addView(customView1, params4);
    
                //add a tag to a view and add a clicklistener to the view
                customView1.setTag(someTag);
                customView1.setOnClickListener(myClickListner);
    
    
    
            }
        });
    

    the clicklistener – create a class variable for it

    OnClickListener myClickListener = new onClickListener(){
        @Override
        public void onClick(View v) {
    
            if(v.getTag() == someTag){
                 //do stuff
            }else if(v.getTag() == otherTag){
                 //do something else
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am adding the LinearLayout(child view) to another LinearLayout(parentview) programatically here I want to
Answered I have a RelativeLayout where I am adding views dynamically as the user
I have HorizontalScrollView with child Layout inside. After adding view into child layout I
Adding more than one child to a WPF StatusBar results in poor layout with
I am programmatically adding a view to the Layout and after i add that
I have 1 view controller acting as a CustomViewContainer and it has 2 child
I have a view, which is having two sub views, while adding those two
My parent view is a RelativeLayout, I added a triangle to it extending the
I have two views (UIView) set-up: parent and child view. The child view is
Can you give me a very simple example of adding child view programmatically to

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.