Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android Studio中使用for Loop使许多图像视图可见?_Android_Arrays_Imageview - Fatal编程技术网

如何在Android Studio中使用for Loop使许多图像视图可见?

如何在Android Studio中使用for Loop使许多图像视图可见?,android,arrays,imageview,Android,Arrays,Imageview,我在代码中声明了一堆Imageview,但当我想更改它们的属性时,它根本不起作用 我已经尝试过用不同的句子来声明它,但它不起作用 int NumberOfMedals= UserData.getInt("USRNBRFMDLS",5); ImageView[] Medals=new ImageView[] {findViewById(R.id.Main_M1_Img) , findViewById(R.id.Main_M2_Img), findViewById(R.id

我在代码中声明了一堆Imageview,但当我想更改它们的属性时,它根本不起作用

我已经尝试过用不同的句子来声明它,但它不起作用

int NumberOfMedals= UserData.getInt("USRNBRFMDLS",5);

ImageView[] Medals=new ImageView[] {findViewById(R.id.Main_M1_Img) , findViewById(R.id.Main_M2_Img),
            findViewById(R.id.Main_M3_Img) , findViewById(R.id.Main_M4_Img) , findViewById(R.id.Main_M5_Img) ,
            findViewById(R.id.Main_M6_Img) , findViewById(R.id.Main_M7_Img) , findViewById(R.id.Main_M8_Img) ,
            findViewById(R.id.Main_M9_Img) , findViewById(R.id.Main_M10_Img) , findViewById(R.id.Main_M11_Img)};

int aux;
for (aux=NumberOfMedals; aux==0; aux--){
    Medals[aux].setVisibility(View.VISIBLE);
}

如果您能帮助我,我将非常感谢。

您的循环错误,请将其更改为:

for (int i = 0; i < Medals.length; i++){
    Medals[i].setVisibility(View.VISIBLE);
}

如果你的应用程序没有崩溃,首先将它们设置为可见,然后检查它们是否可见。首先,所有11个图像都不可见,我希望使用循环使其中一些图像可见。i、 e.one to fiveI说,如果不工作意味着应用程序不会崩溃,但它不会使按钮可见,那么尝试在按钮可见的情况下启动应用程序,并检查它们是否真的可见。非常感谢。我的代码的问题是Aux==0。而且我的图像文件也崩溃了!