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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:57:49+00:00 2026-06-10T21:57:49+00:00

I have been trying to develop an Android app of a simple sound board,

  • 0

I have been trying to develop an Android app of a simple sound board, which will play several long sounds, and only one at a time, not simultaneously. I have the sound part playing great. I want to assign text for each button.

I have a strings.xml set up like so:

<string name="quote01">quote01</string>
<string name="quote02">quote02</string>
<string name="quote03">quote03</string>

In my main.xml, I have my buttonIds set up like this:

    final int[] buttonIds = { R.id.button01, R.id.button02, R.id.button03, 
        R.id.button04, R.id.button05, R.id.button06, 
        R.id.button07, R.id.button08, R.id.button09, 
        R.id.button10, R.id.button11, R.id.button12, 
        R.id.button13, R.id.button14, R.id.button15, 
        R.id.button16, R.id.button16, R.id.button17, 
        R.id.button18, R.id.button19, R.id.button20, 
        R.id.button21, R.id.button22, R.id.button23, 
        R.id.button24, R.id.button25 };

I could just assign the button text like this to get it to work:

Button s01 = (Button) findViewById(R.id.button01); 
s01.setText(this.getString(R.string.quote01));
Button s02 = (Button) findViewById(R.id.button02); 
s02.setText(this.getString(R.string.quote02));
Button s03 = (Button) findViewById(R.id.button03); 
s03.setText(this.getString(R.string.quote03));

But I’d rather use a loop to avoid repetitive code. I have a non-working loop like the below:

for(int i = 0; i < buttonIds.length; i++) { 
    Button soundButton = (Button)findViewById(buttonIds[i]); 
    soundButton.setText(this.getString(R.string.buttonIds[i]);
}

But in the 3rd line above, buttonIds can’t be resolved to a field. I have tried putting brackets or parantheis around the buttonIds[1] but my syntax isn’t right. I am sure this is a super easy question, but it is illuding me. Any suggestions?

Thanks in advance!
Maytag87

  • 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-10T21:57:51+00:00Added an answer on June 10, 2026 at 9:57 pm

    See if this helps:

    Resources res = getResources();
    for(int i = 0; i < buttonIds.length; i++) { 
        Button soundButton = (Button)findViewById(buttonIds[i]); 
        soundButton.setText(res.getIdentifier("quote" + (i < 10 ? "0" + i : i), "string", getPackageName()));
    }
    

    Also your Strings set start from quote01 and the loop starts from i = 0, so you have to synchronize the two values.

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

Sidebar

Related Questions

I have been trying to develop an Andriod app of a simple sound board,
I have been trying to develop an Android app which lets the user take
I have been trying to develop an app for my ipad which i can
I have been trying to develop an app that will deal with content providers
I have been trying to develop a peer to peer application that uses Micosoft's
I have been trying to develop a Core Data piece of code and have
I have been trying to create a ListView which I can sort using drag
I have been trying to develop a Java ME application using WTK 2.5.2 (Java
I am very new to java and trying to develop an Android app called
I have been trying to develop an application in a landscape mode so I

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.