2012-04-10 43 views
0

我需要生成的實例名稱每個thime都不同,例如blocktitle1,blocktitle2,blocktitle3等等。我已經放了一些代碼來改變字符串變量「標題」,但只是把「標題」這個單詞放在一個新的位圖中,這樣就會使實例名爲「標題」而不是「blocktitle2」。每次生成實例標題不同的bimaps?

在任何人的幫助下,我都會非常高興。

List<Block> blocks = new LinkedList<Block>(); 
Random rnd = new Random(System.currentTimeMillis()); 

int randomx = 400; 
public Block block; 
int blocknum = 10; 
String Title = "blocktitle" + blocknum; 


public void generateBlocks(){ 

      if(blocknum > 0){ 

       int offset = rnd.nextInt(400) + 100; //500 is the maximum offset, this is a constant 
       x += offset;       //ofset will be between 100 and 400 

       // i need the word below "block" to be recognised as a String variable "String Title" 
      block = new Block(BitmapFactory.decodeResource(getResources(), R.drawable.block), randomx, 200); 
       blocknum -= 1; 


    } 

} 

回答

0

試試這個:

private static final String titlePrefix = "blocknum"; 
private static int titleNo = 0; 
public String getNextTitle() { 
    return titlePrefix + titleNo++; 
}