나는 의지를 잃을 수도 있습니다. ImageAdapter를 사용하는 Gridview에서 이미지를 뒤섞는 방법을 쓰려고했습니다. 나는 안드로이드에서 경험이 없다. 반복없이 어레이를 이동하는 것과 관련된이 사이트의 모든 질문에 액세스했습니다. 나는 정상적인 자바 환경에서 그것들을 테스트했다. 반복없이 작동하는 것들이 있습니다. 배열을 Arraylist로 바꾸려고 시도하고 Collections.shuffle을 사용했습니다. 난 아직도 반복 또는 에뮬레이터를 추락했다. 나는이 사실에 대한 통찰력을 진심으로 감사 할 것입니다. 그것은 아마도 단순한 것이지만 그것을 얻을 수는 없습니다. 다음은 (내가 찾은 코드를 사용하여) 몇 가지 방법입니다. 다른반복되지 않은 Gridview 항목을 셔플 링하면 여러 가지 방법으로 시도했습니다.
static int[] shuffleArray(int[] ar)
{
Random rnd = new Random();
int randomNo = rnd.nextInt()*3;
// int randomNo = (int)Math.floor(Math.random() * 3);
for (int i = ar.length - 1; i >= 0; i--)
{
// int index = rnd.nextInt(i + 1);
int index = randomNo - 1;
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
return ar;
}
public static void shuffleAArray(int[] a) {
int n = a.length;
int random = randomInt(0,35);
// random.nextInt();
for (int i = 0; i < n; i++) {
int change = i + random;
swap(a, i, change);
}
}
public Integer[] myShuffleS(Integer []ji){
ArrayList<Integer> numbers = new ArrayList<Integer>();
Random randomGenerator = new Random();
while (numbers.size() < 36) {
int random = randomGenerator.nextInt(35);
if (!numbers.contains(random)) {
numbers.add(random);
}
}
for (int i=0; i<ji.length;i++) {
ji[i] =ji[numbers.get(i)] ;
// i++;
}
return ji;
}
다른
public Integer[] myShuffle(Integer[]jigX){
boolean found = false;
for (int i = 0; i < jigX.length; i++) {
do {
found = false;
int temp = randomInt(0,35);
jigX[i] = temp;
for (int j = 0; j < i && !found; j++) {
if (jigX[j] == temp)
found = true;
}
}
while (found);
}
return jigX;
}
도 Collections.shuffle을 시도하고 이미지를 얻기 위해 다음 조각에 넣어
myShuffleS(jigX);//or whatever method
imageView.setImageResource(jigX [position]);
사람이 wirh을 도울 수있는 경우 이건 좋을거야! 고마워요
SimonSays에 답해 주셔서 감사합니다. 여러 번 시도해 보았습니다. 내일 또 다른 시도를 드리겠습니다. –
감사합니다. SimonSays하지만 여전히 반복됩니다. –
입력 배열에 반복 번호가없는 한 출력 배열에는 어느 쪽이든이 방법으로. 입력 배열에 반복 숫자가 포함될 수 있으면 먼저 필터링해야합니다. 예를 들어 Set을 사용할 수 있습니다. – SimonSays