图像随机化Eclipse Java Android

时间:2015-01-08 15:58:43

标签: java android eclipse mobile

目前在eclipse android中使用一个按钮随机化两个图像视图时出现问题,我已经设法使用一个按钮随机化一个图像视图,但无法弄清楚如何使用一个按钮随机化两个图像视图。

到目前为止我有这个代码:

import java.util.Random; 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ImageView; 
import android.view.View.OnClickListener; 

public class randomIMG extends Activity implements OnClickListener{


private Integer [] mImageIds = { 
R.drawable.img_one,
R.drawable.img_two,
enter code hereR.drawable.img_three,
R.drawable.img_four,
R.drawable.img_five,
R.drawable.img_six,
};


private static final Random rgenerator = new Random();
private ImageView iv;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_random_IMG);

Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
iv = (ImageView) findViewById(R.id.imageView1);
iv.setImageResource(q);

View nextButton = findViewById(R.id.button1);
nextButton.setOnClickListener(this);

}

private static final Random rgenerator2 = new Random();
private ImageView ib;



public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Integer p = mImageIds[rgenerator.nextInt(mImageIds.length)];
iv.setImageResource(p);
break;
}

}

}

任何帮助都会很棒。

0 个答案:

没有答案