I am developing an app which has 9 image views in a 3×3 matrix.
I want to change their image if a user clicks them.
So tat requires linking 9 ids and 9 set on click listeners
Is it possible to access them using a for loop like this
public int[] imv= {R.id.im0, R.id.im1, R.id.im2, R.id.im3,R.id.im4, R.id.im5, R.id.im6, R.id.im7,R.id.im8};//Loading ids into array imv
for(int i=0;i<imv.length;i++)
{
ImageView im[i] = (ImageView) findViewById(imv[i]);//Attaching ids
}
for(int i=0;i<imv.length;i++)
{
im[i].setOnClickListener
}
I am getting an error with im[i]. But if I remove i I get an object im which is a collection of imageviews. How can I access the individual imageviews and set onclicklisteners?
I think it will be better to go for GridView refer to this example
http://developer.android.com/resources/tutorials/views/hello-gridview.html
you can write your logic in getView method using imageView.setOnClickListener