1

I am new to Android. I have one edit text when I click on it keyboard is showing automatically. But what I want to do is when user double tab on edit text should show the keyboard. How can I achieve it?

 <Edit Text
            android:id="@+id/TV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="type something"/>

Here I take simple edit text.I take one Gesture Listener class to achieve double tap listener event.

Cœur
  • 32,421
  • 21
  • 173
  • 232
sunita
  • 460
  • 6
  • 19
  • Refer this link http://stackoverflow.com/questions/18977187/how-to-hide-soft-keyboard-when-activity-starts – ajantha Mar 02 '16 at 11:55

2 Answers2

0

Why not use OnLongClickListener to achive what you want?

yourEditText .setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                //show your keyboard
                return false;
            }
        });

hide soft keyboard when click on edit text

  yourEditText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                 InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }       

            }
        });

Here also read this post Android: How to detect double-tap? may help you to understand

Community
  • 1
  • 1
Kristiyan Varbanov
  • 2,293
  • 1
  • 14
  • 27
0

Find the below code, it will check that the edittext is opened or not. If it is opened it will close it

     yourEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            yourEditText= this.getCurrentFocus();
            if (yourEditText!= null) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);

                if (imm.isAcceptingText()) {
                    imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
                }
            }

        }
    });
Attiq ur Rehman
  • 465
  • 1
  • 5
  • 20