【发布时间】:2015-11-28 23:16:05
【问题描述】:
我想完成一个任务,它为变量randomButton 赋值。最后,我想检查randomButton 的值,如果是我不喜欢的东西,我想重新执行我为randomButton 赋值的任务。
我想做这个任务:
int i = rng.nextInt(4); //Find random button from between 1-4
randomButton = buttons.get(i);
buttonBackground = randomButton.getBackground();
Log.v(TAG, "In the do");
如果
buttonBackground.equals(R.drawable.redcircle)
我想再试一次。我该如何实现...?
我试过了:
do {
int i = rng.nextInt(4); //Find random button from between 1-4
randomButton = buttons.get(i);
buttonBackground = randomButton.getBackground();
Log.v(TAG, "In the do");
}while(!buttonBackground.equals(R.drawable.redcircle));
但这是一个无限循环。那么如果值是我不喜欢的东西,我该如何重复任务呢?
顺便说一句,buttons 是一个包含不同图像按钮对象的数组列表。我想看看那个图像按钮(randomButton)的背景是否是红色圆圈。如果是,我想再次浏览代码。如果不是,那就太好了,我可以继续。
【问题讨论】:
-
将时间设置为正确的值(你不喜欢的东西)并确保有时它可能是你喜欢的东西,因此现在它永远不会是 R.drawable.redcircle
-
我认为你的问题在于
buttonBackground.equals(R.drawable.redcircle)。R.drawable.redcircle是int。你到底想做什么? -
@PetterFriberg 是的,我确信 buttonBackground 可以等于除了可绘制的 redcircle 之外的其他东西。我的按钮数组列表
buttons包含四个具有不同可绘制对象的按钮...所以有时是红色圆圈... -
你有!之前所以它需要是 R.drawable.redcircle 的 int 值
-
@PetterFriberg 哦。我只是想检查背景图像是否是红色圆圈。这就是我放的原因!说不相等。我应该怎么做?
标签: java android arrays eclipse string