0

If I understand correctly

    Random ran = new Random();
    String[] ButtonText = null;
    Resources res = getResources();
    ButtonText = res.getStringArray(R.array.ButtonText_array);
    String strRandom = ButtonText[ran.nextInt(ButtonText.length)];
    System.out.println("Random string is : "+strRandom);

Is a way to take my string-array items and put them in random order and now I'm wanting to setText of several buttons with individual items from the strRandom. The following is for the setText of a button

    Button gm1 = (Button) findViewById(R.id.gm1);
    gm1.setText();

But I dont know how to put in the strRandom items into the setText part and since I dont need it displaying what do I need to alter here.

System.out.println("Random string is : "+strRandom);

2 Answers 2

2

I really am not understanding the question...

If you're just asking how to set the text to a random string, do it just as you did with the println() statement,

gm1.setText(strRandom);

or

gm1.setText(ButtonText[ran.nextInt(ButtonText.length)]);

Just a side note: by convention, variables are done in camelCase, reserve AllCaps for class names. (e.g. ButtonText should be buttonText). You'll notice the SO formatter formats ButtonText as if it were a class, not an array.

Sign up to request clarification or add additional context in comments.

Comments

0
gm1.setText((CharSequence)("Random string is : " + strRandom));

You need to cast from String to CharSequence

1 Comment

It's not necessary to cast to CharSequence from a String.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.