0

I have added a setOnTouchListener to EditText in order to scroll the screen when the user click on it. It works, but in the first click it scroll and only in the second click the EditText get focused and open the soft keyboard. How can I make the EditText get focused in the first click and not only in the second?

et_email = (EditText) view.findViewById(R.id.editEmail);

et_email.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        ScrollView scrollView = (ScrollView) getView().findViewById(R.id.ScrollViewSendDetails);
        scrollView.smoothScrollTo(0, et_email.getBottom() + 200);
        return false;
    }
});

btw I tried to add this, but it doesn't help

Community
  • 1
  • 1
Yuval Levy
  • 2,397
  • 10
  • 44
  • 73

1 Answers1

0

Use predefined method

   et_email = (EditText) view.findViewById(R.id.editEmail);

    et_email.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ScrollView scrollView = (ScrollView) getView().findViewById(R.id.ScrollViewSendDetails);
            scrollView.smoothScrollTo(0, et_email.getBottom() + 200);
            // method you can use to focus on edittext
            et_email.requestFocus();

            return false;
        }
    });
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
koutuk
  • 832
  • 1
  • 8
  • 17