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

  • Home
  • SEARCH
  • 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 9177623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:22:06+00:00 2026-06-17T17:22:06+00:00

I like to display some strings from a string array in to a Textview,

  • 0

I like to display some strings from a string array in to a Textview, randomly. I am using the following code for that, But the problem is that most of the time some string is displayed repeatedly.What I want is the strings once displayed should not be displayed again.I have spent hours in searching for the code, but none of them work for me. Kindly help. Thanks in advance.

public void GetQuotes(View view) {
     Resources res = getResources();
            myString = res.getStringArray(R.array.Array);
            String q = myString[rgenerator.nextInt(myString.length)];                               
            TextView tv = (TextView)findViewById(R.id.textView1);               
            tv.setText(q);  
  • 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-17T17:22:07+00:00Added an answer on June 17, 2026 at 5:22 pm

    Java has built in array shuffling method, put all your items into a list, shuffle it randomly, and get the first element till it has elements. If empty, add all elements again, and shuffle again:

    private List<String> myString;
    
    public void GetQuotes(View view) {
        Resources res = getResources();
        if (myString==null || myString.size()==0) {
            myString = new ArrayList<String>();
            Collections.addAll(myString, res.getStringArray(R.array.Array));
            Collections.shuffle(myString); //randomize the list
        }
        String q = myString.remove(0);
        TextView tv = (TextView)findViewById(R.id.textView1);
        tv.setText(q);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use custom fields to display some page specific strings in the
I like to display some (X)HTML content in a Qt application using QtWebKit. The
I have some text that I always need to display (like a HUD). When
I would like to display other we pages in my mobile webapp, but some
I'm extracting some string data from a plist: <dict> <key>Feb 7, 2000</key> <array> <string>7</string>
I'm creating some JButtons from a String array for a menu. Those buttons are
I received the error while trying to display some variable like so: echo id
This has happened since yesterday, some razor views display like this in visual studio:
I have a UILabel that displays some chars. Like x, y or rpm. How
Following on from a recent post. I am creating a search function that queries

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.