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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:18:01+00:00 2026-06-08T07:18:01+00:00

private int info = 1; public void nextStep(View view) { TextView textInfo = (TextView)

  • 0
private int info = 1;

public void nextStep(View view)
{    
    TextView textInfo = (TextView) findViewById(R.id.textInfo);
    textInfo.setText(R.string.info1);
    info++;
}

When one button is clicked, method nextStep is called. And every time a button clicked, I want to show different info, first time it’s info1 string, next time it’s info2 string and etc. from strings.xml. I would like to do something like that:

private int info = 1;

public void nextStep(View view)
{    
    TextView textInfo = (TextView) findViewById(R.id.textInfo);
    textInfo.setText(R.string.info + info);
    info++;
}

Of course, it’s not possible. What should I do? I really don’t want to write a big if/else or switch statement. 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-08T07:18:02+00:00Added an answer on June 8, 2026 at 7:18 am

    Of course, it’s not possible.

    Actually, it is. You can use getIdentifier to do this:

    private int info = 1;
    public void nextStep(View view)
    {    
        TextView textInfo = (TextView) findViewById(R.id.textInfo);
        int myStrId = textInfo.getContext().getResources().getIdentifier("info"+info, "string", textInfo.getContext().getPackageName());
        textInfo.setText(myStrId);
        info++;
    }
    

    getIdentifer() is a way to fetch resource IDs that are stored in R if you don’t know the exact name. While it isn’t the most efficient method in the world, it suffices in situations where referencing R (such as your situation) is not possible.

    The method returns the same ID that R would; that is, getIdentifier("info1", "id", ...); is the same as R.id.info1, since R is just a compiled version of it. This method also works in the event that you are unsure if an ID exists (such as from an external library) but need to reference it anyway.

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

Sidebar

Related Questions

public class Ex7 { private int fld; private void meth(int val) { fld =
public class ExpAdapter : BaseExpandableListAdapter { private int seed = 1000; public override View
Suppose we have two classes: class Base { private: int x; public: void f();
So, I have this class: public class Product { private String name, id, info
@Entity @Table(name=Product_info) public class Product { private int ProductIndex; private int priority; private Date
private int Index(String[] match,String keyword){ int m=0; keyword=keyword+1; match[m]=match[m]+1; System.out.println(match:+match[m]); System.out.println(keyword:+keyword); System.out.println(match[m].equals(keyword)); while(!(match[m].equals()) &&
public class Arrys { private int[] nums; //Step 3 public Arrys (int arrySize) {
class Celda { private: int* bloques_; public: Celda(int size); ~Celda(){ delete [] bloques_; };
public class Checker { static private int value1 = 0, value2 = 1; static
I have the following class: @Entity @Table(name=tbl_books) public class Book{ private int id_book; private

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.