嗨,我有一个问题,同时创造的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这一点。 –
不要想随机显示图片,或者在一个和下一个序列。 –