Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll to form element

I have a form with lots of fields and when I press the "submit" button, I'd like the scrollview to jump to the position where the unanswered field is located. Is there a method other than scrollto(x,y) to do this or such coordinates must always be mapped to the form's elements somehow ( something like (form element).getCoordinates() )?

Thanks

like image 507
xain Avatar asked Feb 25 '23 12:02

xain


1 Answers

This should work -

view.setFocusableInTouchMode(true);
view.requestFocus();
view.requestRectangleOnScreen(viewRectangle);

You can always take a look at the View class.

P.S. The unanswered field will be selected but I'm not sure that if it is out of the screen the Activity will scroll to the requested position.

like image 56
Kiril Kirilov Avatar answered Feb 28 '23 03:02

Kiril Kirilov