안드로이드 개발 질문/답변
(글 수 45,052)
package com.android.Test5;
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;
public class Test5 extends Activity { public int i; public static final int array[]= { R.drawable.snc00581, R.drawable.snc00582, R.drawable.snc00583, R.drawable.snc00584, R.drawable.snc00585, R.drawable.snc00586, R.drawable.snc00587, R.drawable.snc00588, R.drawable.snc00590, R.drawable.snc00560 }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { TextView t = (TextView)findViewById(R.id.text); t.setText("클릭됨~"); ImageView test = (ImageView)findViewById(R.id.imageView1); test.setImageResource(array[i]); //test.setImageResource((int)(System.currentTimeMillis()%10)); //array[i]++; } }); } }
버튼을 클릭할때마다 array배열에 저장되어있는 10개의 이미지를 중복되지 않고 랜덤하게 출력하고 싶습니다.
중복되지않고 10개 다 출력하면 더이상 이미지가 안나오는것이지요;;;
아제가 아까 질문을 이상하게 해석했네요~죄송합니당(__)
이건 Math.random() 함수를 써서 i에 0~10까지 들어가게 조절한다음에
나온숫자를 하나씩 저장해뒀다가 다음번 클릭때 그숫자가 또 나오면 ㄹ다시 랜덤을 돌리는 식으로 하면 되지 않을까요?