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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:49:57+00:00 2026-05-24T04:49:57+00:00

I have a layout to be inflated in another layout dinamically for each category:

  • 0

I have a layout to be inflated in another layout dinamically for each category:

LinearLayout l = (LinearLayout) findViewById(R.id.container);

        for (CategoryEB e :categoryList){
            LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout linLayout = (LinearLayout)layoutInflater.inflate(R.layout.inflated_layout, l);
            TextView view = (TextView)linLayout.findViewById(R.id.lable);
            view.setText(e.getName());
        }

this is the xml to be inflated (inflated_layout.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:id="@+id/lable"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="xxx"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:paddingLeft="6dip"/>

</LinearLayout>

but in this way only the first item gets populated with the correct value. The other ones of the categoryList are shown as xxx (as described in the xml).

How can I display all the correct names in the list?

  • 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-24T04:49:59+00:00Added an answer on May 24, 2026 at 4:49 am

    The problem is that linLayout will point to your main layout container, l. So that you will only find the first instance of a view with id R.id.label.

    One simple solution would be to change the id of the label once you’ve initialized it. Something like this:

    LinearLayout l = (LinearLayout) findViewById(R.id.container);
    
        for (CategoryEB e :categoryList){
            LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout linLayout = (LinearLayout)layoutInflater.inflate(R.layout.inflated_layout, l);
            TextView view = (TextView)linLayout.findViewById(R.id.lable);
            view.setText(e.getName());
            view.setId(0);  //this way you wont find the same view twice.
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a layout similar to this: <div id=...><img src=...></div> and would like to
I have a layout 'profile' <div> <div> $this->action(action1, controller1, module1)<div> <div> $this->layout()->content </div> <div>
I have this layout that works correctly, a relative layout with a text view
I have a listactivity which contains a listview. i want to show another layout
I have a class that extends Activity and inflates another xml layout in the
I have a ListActivity where the list items are defined in another XML layout.
I have a layout which uses min-width and works great. So I came to
I have a layout that is working, but it has one very annoying problem..
I have a layout in which I am displaying a webview . I want
I have the layout as follows: <div id=outerwrap> <div id=innerwrap> <div id=centerc>...</div> <div id=rightc

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.