android - using multiple string arrays and getting string arrays dynamically -
i want use random number generator pick 1 of cards stored in .xml file string array.
currently know can change text view calling
string[] cards = getresources().getstringarray(r.array.card1); text1.settext(cards[0]); text2.settext(cards[1]); text3.settext(cards[2]); text4.settext(cards[3]); text5.settext(cards[4]); text6.settext(cards[5]);
and load items in string array correctly.
my question when random number generated, how can use number to
.getstringarray(r.array.cardx);
where x integer generated can randomly generate list of strings every time. think looking input variable .getsringarray(x) i'm not sure how that. if have other suggestions on how well. help
if understand correctly, have several string array resources want pick @ random.
unfortunately, resource ids generated variables, , there no way generate resource id string. if @ r.java
in build directory, notice resource ids declared actual variables in there.
the way have creating list of resource ids selected so:
import java.util.random; int[] cardstringresourceids = { r.array.cards1, r.array.cards2, r.array.cards3, }; random random = new random(); int randomindex = random.nextint(cardstringresourceids.length); string[] cards = getresources().getstringarray(cardstringresourceids[randomindex]);
Comments
Post a Comment