开发者

Doing this with a for cycle

And now a very easy java question....

        Object[] objectList={
            new Object(name[0], description[0], R.drawable.creep_0),
            new Object(name[1], description[1], R.drawable.creep_1),
            new Object(name[2], description[2], R.drawable.creep_2),
            new Object(name[3], descr开发者_运维知识库iption[3], R.drawable.creep_3),
};

How can i do this dynamically with a for cycle? Thanks!


Creep[] creeps = new Creep[] 
    { R.drawable.creep_0, R.drawable.creep_1, R.drawable.creep_2, 
      R.drawable.creep_3 };
Object[] objectList = new Object[4];
for (int i = 0; i < 4; i++) {
    objectList[i] = new Object(name[i], description[i], creeps[i]);
}


ArrayList objectList = new ArrayList(); 
for (int i = 0; i < 4; i++)
{
     Object o = new Object(name[i], description[i], R.drawable.creep_i);
     objectList.Add(o);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜