Java 迭代GridLayout子项以隐藏3x3板的图像视图
我一直试图隐藏GridLayout 3x3板的所有图像视图。我尝试使用循环遍历布局和imageView.setImageDrawable(null)的所有子级 注意:以下代码已放置在PlayReach(查看)按钮方法中Java 迭代GridLayout子项以隐藏3x3板的图像视图,java,android,Java,Android,我一直试图隐藏GridLayout 3x3板的所有图像视图。我尝试使用循环遍历布局和imageView.setImageDrawable(null)的所有子级 注意:以下代码已放置在PlayReach(查看)按钮方法中 public void playAgain(View view){ Button playAgainButton = (Button) findViewById(R.id.playAgainButtonID); TextView winnerTe
public void playAgain(View view){
Button playAgainButton = (Button) findViewById(R.id.playAgainButtonID);
TextView winnerTextView = (TextView) findViewById(R.id.winnerTextView);
playAgainButton.setVisibility(View.INVISIBLE);
winnerTextView.animate().translationYBy(-100);
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
for(int i=0; i<gridLayout.getChildCount(); i++){
ImageView imageView = (ImageView) gridLayout.getChildAt(i);
imageView.setBackgroundResource(0);
}
public void再次播放(视图){
按钮playAgainButton=(按钮)findViewById(R.id.playAgainButtonID);
TextView winnerTextView=(TextView)findViewById(R.id.winnerTextView);
playAgainButton.setVisibility(View.INVISIBLE);
winnerTextView.animate().translationBy(-100);
GridLayout GridLayout=(GridLayout)findViewById(R.id.GridLayout);
对于(int i=0;i来说,您似乎在铸造错误版本的GridLayout
java.lang.ClassCastException:android.support.v7.widget.GridLayout无法转换为com.rootcomp.bills.joincoin.MainActivity.PlayReach(MainActivity.java:99)上的android.widget.GridLayout
您是否在xml中使用支持版本,在代码中使用非支持版本
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
它们都被称为GridLayout,但来自不同的库。如果没有其他方法有效,您可以始终编写imageView.setVisibility(View.INVISIBLE);
这样您甚至可以跳过转换到imageView
:GridLayout.getChildAt(i).setVisibility(View.INVISIBLE);
我认为问题在于我用来迭代GridLayout的所有子项的for循环。当我注释掉循环行时,它工作正常,在尝试使用循环时出现崩溃。只使用了imageView.setVisibility(View.INVISIBLE);遗憾的是,仍然是相同的错误。然后在Logcat中查找崩溃日志。它说了什么?for(int i=0;iUmmm…这不是我要问的。您使用Android Studio吗?现在已替换”