I have a layout(like board) like this that contains cells(buttons)
| A | B | C | D |
-----------------
| E | F | G | H |
-----------------
| I | J | K | L |
-----------------
| X | Y | Z | W |
I'm adding Cells programmatically, they contains letters I set.
public void addCells(String letters){
removeAllViews();
int let = 0;
for (int j = 0; j < 4; j++){
for (int i = 0; i < 4; i++){
String currentLetter = ""+letters.charAt(let);
//Cell object that contains it's position and letter.
Cell cell_ = new Cell(this.getContext(), new Point(i , j), new Letter(currentLetter));
this.addView(cell_);
this.cells[i][j] = cell_;
let++;
}
}
}
My aim is connecting cells by finger moving like this:
I'm returning true
from onTouchEvent()
so I can capture all touchs in ViewGroup onInterceptTouchEvent()
public boolean onTouchEvent(MotionEvent motionEvent) {
return true;
}
But I couldn't get the logic. How can I access a certain child object by click/touch in that ViewGroup?
When I click to 'A' letter, I want to access that cell object.