这是简短的版本。我有一个奖励活动,它有 25 个可点击的图像视图。我需要的是当单击一个 ImageView 时,所有其他的都需要设置为启用(假)。我想在 for 循环中执行此操作。我所拥有的一个例子如下。有什么建议么
private ImageView img1;
private ImageView img2;
private ImageView img3;
private ImageView img4;
private ImageView img5;
private ImageView img6;
private ImageView img7;
private ImageView img8;
private ImageView img9;
private ImageView img10;
private ImageView[] imageview = {img1,img2,img3,img4,img5,img6,img7,img8,img9,img10};
int i = 0;
int imgv =0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.bonus_layout);
img1 = (ImageView) findViewById(R.id.imageView1);
img2 = (ImageView) findViewById(R.id.imageView2);
img3 = (ImageView) findViewById(R.id.imageView3);
img4 = (ImageView) findViewById(R.id.imageView4);
img5 = (ImageView) findViewById(R.id.imageView5);
img6 = (ImageView) findViewById(R.id.imageView6);
img7 = (ImageView) findViewById(R.id.imageView7);
img8 = (ImageView) findViewById(R.id.imageView8);
img9 = (ImageView) findViewById(R.id.imageView9);
img10 = (ImageView) findViewById(R.id.imageView10);
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(rank[b]==0){
for(i<25) imageview.get(i) setEnabled(false);
(i++);
//This example offered get a force close for(ImageView iv:imageview)iv.setEnabled(false);
}
}} });
这是您帮助我的更正代码
public class BonusActivity extends Activity implements View.OnClickListener
{
Integer rank[]= {0,100,200,300,0,400,500,0};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.bonus_layout);
final ImageView img1 = (ImageView) findViewById(R.id.imageView1);
final ImageView img2 = (ImageView) findViewById(R.id.imageView2);
final ImageView img3 = (ImageView) findViewById(R.id.imageView3);
final ImageView img4 = (ImageView) findViewById(R.id.imageView4);
final ImageView img5 = (ImageView) findViewById(R.id.imageView5);
final ImageView img6 = (ImageView) findViewById(R.id.imageView6);
final ImageView img7 = (ImageView) findViewById(R.id.imageView7);
final ImageView img8 = (ImageView) findViewById(R.id.imageView8);
final ImageView img9 = (ImageView) findViewById(R.id.imageView9);
final ImageView img10 = (ImageView) findViewById(R.id.imageView10);
final ImageView[] imageview ={img1,img2,img3,img4,img5,img6,img7,img8,img9,img10};
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(rank[b]==0){
img1.setImageResource(R.drawable.empty);
for(int i = 0; i<imageview.length;i++)
{imageview[i].setClickable(false);}