Pratik Sharma
Pratik Sharma

Reputation: 13415

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?

Upvotes: 0

Views: 2362

Answers (2)

Joshy Francis
Joshy Francis

Reputation: 349

 Rect rectangle=new Rect();
 row.getDrawingRect(rectangle);
 row.requestRectangleOnScreen(rectangle);

tested and it is working. Thanks to @CR

Upvotes: 0

CR.
CR.

Reputation: 364

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.

Upvotes: 1

Related Questions