经过漫长的斗争,我得到了一个解决方案。这就是我所做的。
我有一个标志阵列“国家[]”和三个图像按钮声明为ImageButton array bt[]={id1,id2,id3};
,我用下面的代码使用:
public void randomDisplay()
{
L=Country.length;
for(int i=0; i<3;i++)
{
int random=rand.nextInt(L-1);
if(i==0)
id1=Country[random];
if(i==1)
id2=Country[random];
if(i==2)
id3=Country[random];
id=getResources().getIdentifier(Country[random], "drawable", getPackageName());
bt[i].setImageResource(id);
String temp=Country[L-1];
Country[L-1]=Country[random];
Country[random]=temp;
L=L-1;
}
}
上面的代码将一个国家名称转向的端部国家数组,每次重复,并减少国家数组的长度。这将避免ImageButton上的重复名称。如果您有任何问题,请告诉我...