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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:52:29+00:00 2026-06-04T15:52:29+00:00

I setup this loop, and it works fine, but I would like to be

  • 0

I setup this loop, and it works fine, but I would like to be able to change each textView individually, so I need to setup textView.setId(whateveryouputinhere); Could someone please explain to me how to setup the id and what you put inside the parenthesis? Thanks!

while (counter < 5) {
            view = LayoutInflater.from(getBaseContext()).inflate(R.layout.newplayerlayout, null);
            parent.addView(view); 
            TextView textView = (TextView) view.findViewById(R.id.textView2);
            textView.setText("Player "+counter);
            textView.setId(counter);
            counter++;

        }
  • 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-04T15:52:30+00:00Added an answer on June 4, 2026 at 3:52 pm

    I setup this loop, and it works fine, but I would like to be able to change each textView individually

    ok

    so I need to setup textView.setId(whateveryouputinhere);

    no you don’t, there are better ways to achieve what you are trying to do.

    One example might be something like this:

    LayoutInflator mInflator; //You are creating 5 of these with your code, you don't need to.
    mInflator = LayoutInflater.from(this); //Your activity is a context. So you pass it in, instead 
                                           //calling getBaseContext(). Which you should try avoid generally.
    TextView[] mTxts = new TextView[5](this);
    while (counter < 5) {
        mTxts[counter] = (TextView)mInflator.inflate(R.layout.newplayerlayout, null);
        parent.addView(view); 
        //TextView textView = (TextView) view.findViewById(R.id.textView2);
        //You don't need this any more.
    
        mTxts[counter].setText("Player "+counter);
        //textView.setId(counter);
        //don't need this either.
        counter++;
    }
    //Now that your array is loaded you can set the text like this:
    mTxts[0].setText("plums");
    mTxts[2].setText("grapes");
    

    Note, I didn’t compile this but it should be close. If you get an error on the “this” change them to “YourActivity.this” with the name of your activity class.

    There are a few benefits, by keeping the LayoutInflater reference you save creating 4 more of those. After you inflate the view object there is no need to then find it by Id, you’ve already got it. You can cast it as a TextView right out of the inflater if you like. By keeping them in an array you can always reference each of them without having to call findViewById() again, this method is rather expensive, you should try to avoid calling it excessively.

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

Sidebar

Related Questions

I want a setup like this: +- /ApplicationFolder -- App.exe -- Core.dll -- AnotherShared.dll
I have a setup like this: <div id=container> <div id=close>Close</div> </div> Then in my
I have a setup like this. var element = $(.module-panel, this.el); $('.module-panel:not('+element+')').hide(); What I'm
Is there any drawback to this setup? I want to be able to run
I have a Drupal setup like this: Content type: Apartments Vocabulary: Areas , that
I have the code below which works fine, steps through the rows pinging each
I have a tool that works perfectly fine in Chrome and FF. But with
Objects in javascript throw me for a loop! In this set up... var obj
Help me please. How to setup this rewrite for nginx 1.0.14? RewriteRule ^([^/]*)\.html$ /?page=$1
I have this setup in my models: class Author(models.Model): name = models.CharField(max_length=100) class Topic(models.Model):

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.