Generating bimaps with the instance title different everytime?

心已入冬 提交于 2019-12-12 05:29:14

问题


i need the generated instance name to be different every thime eg blocktitle1, blocktitle2, blocktitle3 and so on. I have put some code to change the string variable "title" but just putting the word "Title" where im making a new bitmap will make the instance called "Title" not eg "blocktitle2".

I would be very greatfull in anyone were to help.

 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;


    }

}

回答1:


Try this:

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


来源:https://stackoverflow.com/questions/10091089/generating-bimaps-with-the-instance-title-different-everytime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!