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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:35:41+00:00 2026-06-10T20:35:41+00:00

I have 10 LinearLayouts how to identify the each linearlayout, so that onclick of

  • 0

I have 10 LinearLayouts how to identify the each linearlayout, so that onclick of that i need to perform some action on it

Below is the code

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item);


    newsLayout =(LinearLayout)findViewById(R.id.newsLayout);        

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      RelativeLayout rel=null;
        for(int i=0;i<images.size();i++){
            rel= new RelativeLayout(this);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rel.setId(i);
            rel = (RelativeLayout) inflater.inflate(R.layout.reuse,null);

            params.setMargins(0, 50, 0, 0);

             TextView fromWeb= (TextView) rel.findViewById(R.id.text);
             fromWeb.setText(headLines.get(i));
             newsLayout.addView(rel,params);



 rel.setOnClickListener(new RelativeLayout.OnClickListener() {
            public void onClick(View arg0) {   
                switch(arg0.getId())   { 

       case 1: Toast.makeText(DesignShape.this, "clicked"+arg0.getId(),           Toast.LENGTH_LONG).show();       
    break;     

 default: break; 
        }
    } 
});
    }



    }

On click event on linear layout resulting in the same object everytime. how can i distinguih from each other

  • 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-10T20:35:43+00:00Added an answer on June 10, 2026 at 8:35 pm

    You can give the id to the every linearlayout and write a case to getid in the layout on click.

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

Sidebar

Related Questions

i need to have a gridview of linearlayouts. Each linearLayout must have a imageview
I have a Custom ListView that contains a vertical LinearLayout of horizontal LinearLayouts for
I have a LinearLayout with some other LinearLayouts inside. The children layouts have a
I have a LinearLayout with some nested LinearLayouts, ImageView's and TextViews. One of the
Basically, I have a LinearLayout that holds a random amount of horizontal LinearLayouts, and
I have one Master LinearLayout with several other LinearLayouts nested inside of it that
I have a ListView composed of LinearLayouts. Inside each is an ImageView, TextView and
Say I have a LinearLayout with some elements in it as an .xml file.
I have an empty LinearLayout , and I need to add a dynamic number
I have to show some LinearLayouts in Scroll. I am using ListView but got

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.