Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid setText with getString using variable name
    primarykey
    data
    text
    <p>So, searching the internet I found many examples that were not what I need...</p> <p>Here is my situation:</p> <p>Imagine that you have a resource that is an array called songs and many 's with each song name..so, imagina you have like 200 song names displayed on a listview..</p> <p>when you click a song, the app loads another activity with the lyrics for that song... but HOW do you do that?</p> <p>Here is how I did it.. I passed the name of the song to this new activity, loaded the resource where the lyrics are...</p> <p>BUT, at the time I have to setText with the lyrics, I got a problem... should I do a switch with 200 cases? that sounds insane, so, what I did was, I used the same name of the song to the lyrics..so it should load like this:</p> <pre><code>TextView txtProduct = (TextView) findViewById(R.id.product_label); Intent i = getIntent(); // getting attached intent data String[] musicas = getResources().getStringArray(R.array.botafogo_songs); // this here is where it brings the name of the music to the activity String product = i.getStringExtra("product"); // displaying selected product name if (Arrays.asList(musicas).contains(product)) { //just formating so they have the same name. String productSplit = product.split("- ")[1]; productSplit.replace(" ", ""); txtProduct.setText(getString(R.string.AbreAlas)); }else{ txtProduct.setText("não contem"); } </code></pre> <p>Ok, AbreAlas is the name of my resource..it loads fine.. BUT, I cant leave it like this...it should be a variable name... like: <code>R.string.+productSplit</code> or something like this..</p> <p>I can't find the solution nowhere..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload