嗨,我有一個問題,同時創造的ImageView當我點擊前面的(B1)和未來(B2)按鈕,它顯示了一個和上一個圖片來自的img陣列,但有時它顯示隨機圖像Android這樣的版面圖等的ImageButton顯示隨機圖像
public class FullTable extends Activity{
int[] img={
R.drawable.t1,R.drawable.t2,R.drawable.t3,
R.drawable.t4,R.drawable.t5,R.drawable.t6,
R.drawable.t7,R.drawable.t8,R.drawable.t9,
R.drawable.t10,R.drawable.t11,R.drawable.t12,
R.drawable.t13,R.drawable.t14,R.drawable.t15,
R.drawable.t16,R.drawable.t17,R.drawable.t18,
R.drawable.t19,R.drawable.t20};
ImageButton b1,b2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_table);
b1 =(ImageButton) findViewById(R.id.buttonback);
b2=(ImageButton) findViewById(R.id.buttonnext);
// get intent data
Intent i = getIntent();
// Selected image id
final int position = i.getExtras().getInt("id");
final ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
//imageView.setImageResource(imageAdapter.mThumbIds[position]);
imageView.setImageResource(img[position]);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
imageView.setImageResource(img[position]-1);
img[position]--;
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
imageView.setImageResource(img[position]+1);
img[position]++;
}
});
}
}
使用iterator這一點。 –
不要想隨機顯示圖片,或者在一個和下一個序列。 –