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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:53:30+00:00 2026-05-22T18:53:30+00:00

It is a real silly questions but I can’t get it to work. I’ve

  • 0

It is a real silly questions but I can’t get it to work. I’ve used the search option, but couldn’t not find my answer for android.

What I would like to do it the following:

In res/strings.xml i’ve got several strings

<string name="good0">blablabla</string>
<string name="good1">balablabla2</string>
etc

I want to show those strings randomly in a those when something happens:

Toast.makeText(this,R.string.good+(Math.random()*10), Toast.LENGTH_LONG).show();

But this doesn’t work.

Thanks a lot for your help!

  • 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-22T18:53:31+00:00Added an answer on May 22, 2026 at 6:53 pm

    Use a String Array.

    In strings.xml:

    <resources>
        <string-array name="messages">
            <item>blablabla</item>
            <item>blablabla</item>
        </string-array>
    </resources>
    

    Then, in code you will have something like:

    String[] messages = getResources().getStringArray(R.array.messages);
    Random r = new Random();
    String message = messages[r.nextInt(messages.length)];
    Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a real silly mistake in Python but unable to find what it
This is probably a silly question but i haven't been able to find the
real newbie question but why doesn't this work? I am getting use of unassigned
Real odd one to get stuck on but weirdly I am. You you have
Okay this may sound silly, but I am not very familiar with XML. What
A real F# noob question, but what is |> called and what does it
I am doing something that is probably silly, but it would be nice if
This may seem like a silly question, but what are the functional differences, if
Maybe this is a silly question, but I cannot guess how to solve it
I created a silly Huffman compressor in Python, so I can compress image/sound data

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.