Reputation: 111
I am developing an Android App where I have a TableLayout and each cell has an EditText in it. I want to navigate through the cells using four buttons. For example: Two buttons for up-down navigation (same column, different rows) and two buttons for left-right navigation (same row, different columns). Then I want to highlight the cell that has the focus at that moment (e.g. by changing the background color of that EditText).
I want to know if there is a way I can set the focus (for navigation) programmatically and get the index of the focused cell (for highlighting)? Thanks in advance.
Upvotes: 1
Views: 355
Reputation: 561
You can use View.requestFocus() to force focus to a view. For the index, you can use a variable for each axis. For example, everytime the right button is pressed you can increase the value of your x-axis variable by 1. And decrease when the left button is pressed. You should initialize those axis variables correctly.
Upvotes: 1