• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Trying to access imageViews that reside in a TableLayout - Android

I have a TableLayout which has 3 TableRows and within the rows there are 3 ImageViews. What I am trying to do is iterate through the table and setImageResource for each ImageView in the table. I have tried using this code, but I am getting stuck with this problem. I am a beginner at Android, any help is greatly appreciated, thank you.

My code as follows...
TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout);
TableRow tableRow = (TableRow)tableLayout.getChildAt(0);
ImageView imageView = (ImageView)tableRow.getChildAt(0);


int x = tableLayout.getChildCount();
for(int i = 0; i < x; i++){
tableRow= (TableRow)tableLayout.getChildAt(i);
for( int j = 0; j < 3; j++){
imageView = (ImageView)tableRow.getChildAt(j);
imageView.setImageResource(0);
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones