Select a form element

I have a form with many fields, and when I click the submit button, I need the scrollview to move to the position where the unanswered field is. Is there a way other than scrollto (x, y) to do this, or should such coordinates always be mapped to form elements in some way (something like (form element) .getCoordinates ())?

thanks

+4
source share
2 answers

ScrollViews have predefined methods scrollTo () and scrollBy () for such functionality.

I believe that you are having trouble getting the coordinates. Therefore, I suggest storing the height of each view (which uses vertical space) using View.getHeight and storing the height in the Map Collection . Below is the code snippet I tried

scrollView.post(new Runnable() { public void run() { Integer emailTextViewHeight = (Integer)hashMap.get("EmailTextViewHeight"); scrollView.scrollBy(0, emailTextViewHeight);//scrolls to emailTextView } }); 
+2
source

This should work -

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

You can always look at the view class.

PS The canceled field will be selected, but I'm not sure that if it is off the screen, the activity will scroll to the desired position.

+6
source

Source: https://habr.com/ru/post/1333502/


All Articles