<TableRow
android:id="@+id/Row3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="@+id/cell31"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="50sp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@drawable/back"
android:onClick="cellClick"
android:clickable="true"/>
<TextView
android:id="@+id/cell32"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:textSize="50sp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@drawable/back"
android:onClick="cellClick"
android:clickable="true"/>
.... this is 5x5 row column table. with 25 cells in it.
My .xml file looks like this. I have bunch of rows in LinearLayout contains TableLayouts which contains TextViews as cells. I am making a basic game with them. I am trying to assign each cell from .xml to TextView array in .java file. But i can't figure out how to make it. I need to change color of each cell based on some algorithm i made so i want to access of cells.
private TextView colorBoard[][];
this is my .java array.
I can check if they are clicked with
public void cellClick(View v) {
TextView cell = (TextView) findViewById(v.getId());
switch (cell.getId()) {
case R.id.cell11:
xloc = 0;
break;
case R.id.cell12:
xloc = 1;
break ;
...rest of cells
But i only can assign which cell clicked at moment.In my game color of cells change differently. Not the one you just clicked. Assume you clicked 1x3 and 4x4 may change colors.
I'm new to android and this is my first project so sorry if i'm missing something basic.