Set focus to the specific TableRow from the TableLayout in Android

I have one tablelayout and it contains 2 textviews in one row.
All my rows are added dynamically through the activity and my table is in scrollview. So, as rows are added table is scrolled up step by step.

I am also able to maintain all created and added row ids from the tablelayout.

I want to jump back to the row number specified by user.
Let us say, user gives 5 as a row number. So, my table should be scrolled up at row number 5 so that row comes on the screen view and user can see the content of the 5th row.

I am wandering from 2 days to get solution for this, but not getting any method to achieve this.

Does anyone have solution for it?

Answer

To get it to scroll call TableRow.requestRectangleOnScreen() (substitute “TableRow” with the actual TableRow object in your code).

You can use anything for the rectangle coordinates (like 0,0,0,0) but I believe using something like Rect(0, 0, TableRow.getWidth(), TableRow.getHeight()) will make sure the whole row is scrolled so it’s fully on screen.

Actually any View object supports requestRectangleOnScreen() so play around with it.