【发布时间】:2011-05-13 22:59:41
【问题描述】:
大家好 - 在 Android 中,我在我的 string.xml 中写了一些字符串,我想根据随机数在 TextView 上显示...这是我所拥有的:
int randCropPercentage = (int) Math.ceil(Math.random() * 100);
Random randPhrase50 = new Random();
int[] array50 = new int[] { R.string.ss2, R.string.ss4, R.string.ss5,
R.string.st4, R.string.st5, R.string.tt2, R.string.tt3,
R.string.tt5, R.string.to2, R.string.to3, R.string.to4,
R.string.os5 };
int randPhrase = randPhrase50.nextInt(array50.length - 1);
在 if 语句中,我有这个:
if (randomCropPercentage < 50){
mTheMessage.setText(array50(randPhrase));
//etc
但我知道我做的不对,因为我得到了错误:
The method array50(int) is undefined for the type MAIN
有什么想法吗?
【问题讨论】:
标签: android arrays string random textview