Show random string.

Posted by zaid on Stack Overflow See other posts from Stack Overflow or by zaid
Published on 2010-04-26T23:15:30Z Indexed on 2010/04/26 23:33 UTC
Read the original article Hit count: 251

Filed under:

i am trying to display a random string each time a button is pressed from a set of strings defined in strings.xml . this is an example of the strings ID's

<string name="q0">
    <string name="q1">
    <string name="q2">
    <string name="q3">
    <string name="q4">

java code for getting a random string.

private static final Random rgenerator = null;

    int RandomQ = R.string.q0  (rgenerator.nextInt(5) + 1);
    String q = getString(RandomQ);

if i try to use this java code i get an error at "q0" in R.string.q0 which is The method q0(int) is undefined for the type R.string if i try to use the quick fix and create a method, it works. but it wont let me save or run the app because it replaces my create method and shows this message

R.java was modified manually! Reverting to generated version!

thanks for reading.

© Stack Overflow or respective owner

Related posts about android