我做了大约20个字符串的池,每个显示不同的说法。我希望这些说法之一随机显示为文本视图。随机显示字符串
我投一个整数作为随机1-20,
int randomNumber5 = (int) Math.ceil(Math.random() * 20);
,并创建名为字符串randomString1,randomString2,等...直到它击中20
我能想到的最好办法做到这一点,为每个字符串分配1到20之间的数字。
所以:
switch(randomNumber5){
case 1:
mTheMessage.setText(R.string.randomString1);
}
case 2:
mTheMessage.setText(R.string.randomString2);
,但我觉得有一个更好的方式来做到这一点吗?
我该如何将所有的说法放入数组/列表中? – Sapp 2010-11-22 02:28:26
有几种方法:http://www.w3schools.com/js/js_obj_array.asp(我假设你的代码是javascript,但你没有说。) – ddrace 2010-11-22 02:58:29