2010-11-22 13 views
0

こんにちはすべて - Androidでは、string.xmlにいくつかの文字列を書きました。乱数に基づいてTextViewに表示したいと思います。持っている:レイアウト内の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 

アイデア?

array50[randPhrase] 

配列がない()経由の要素へのアクセス権を与えるが、配列へのアクセス[]

答えて

3

事実は、あなたがこれを書くべきである mTheMessage.setText(array50[randPhrase]);

2

[]

である経て、これを試してみてください:

関連する問題