本文介绍了生成bimaps与实例标题不同,每次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要生成的实例名称是不同的每一个thime如blocktitle1,blocktitle2,blocktitle3等。我已经把一些code键更改字符串变量头衔,但只是在前面加上标题,其中IM做一个新的位图将创建一个名为标题没有如blocktitle2的实例。
我会很greatfull在任何人都来帮忙。
列表<嵌段>块=新的LinkedList<嵌段>();
随机RND =新的随机(System.currentTimeMillis的()); INT randomx = 400;
公共block块;
INT的blocknum = 10;
字符串标题=blocktitle+的blocknum;
公共无效generateBlocks(){ 如果(的blocknum大于0){ INT偏移= rnd.nextInt(400)+ 100; // 500是最大偏移,这是一个常数
X + =偏移; // OFSET将是100和400之间 //我需要下面的块这个词被识别为一个字符串变量字符串标题
块=新的块(BitmapFactory.de codeResource(getResources(),R.drawable.block),randomx,200);
的blocknum - = 1;
}}
解决方案
试试这个:
私有静态最后弦乐标题preFIX =的blocknum;
私有静态诠释titleNo = 0;
公共字符串getNextTitle(){
回到标题preFIX + titleNo ++;
}
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;
}
}
解决方案
Try this:
private static final String titlePrefix = "blocknum";
private static int titleNo = 0;
public String getNextTitle() {
return titlePrefix + titleNo++;
}
这篇关于生成bimaps与实例标题不同,每次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!