0

I am Using an EditText and has onEditorActionListener and TextChangedListener. what i want to do is to search for friends when a text is changed and even search for friend when enter is pressed. But the problem is this tha whenever i enter Text in EditText it automatically hide the keyboard. i want to avoid this. How could i do this??

here is what i am doing

searchET.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (actionId == KeyEvent.KEYCODE_ENTER)) {
                searchFriendList(searchET.getText().toString());
                return true;
            }
            return false;
        }
    });

    searchET.addTextChangedListener(new TextWatcher() {


        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) { // TODO Auto-generated method stub
            if (s.length() > 0)
                searchFriendList(searchET.getText().toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) { // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

any help would be greatly appreciated.

Dude
  • 163
  • 1
  • 4
  • 14
  • Clicking on the EditText should ideally not close the Software Keyboard. So you must be doing it, albeit unintentionally. Kindly post all code relating to searchET. Also, look for the word focus in your code. They could be culprits – Anudeep Bulla Jul 15 '14 at 06:13

3 Answers3

3

To show soft keyboard do this:

//Import this
import android.view.inputmethod.InputMethodManager;

//Create object
private InputMethodManager imm;

imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
Badrul
  • 1,462
  • 4
  • 15
  • 26
2

Add android:windowSoftInputMode="stateAlwaysVisible" to your activity in the AndroidManifest.xml file:

<activity android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" />

In my test app this shows the keyboard on starting of the application although it isn't fixed there but can be dismissed by pressing the back button.

To make sure the keyboard is always visible you might have to create your own keyboard as part of your application. Possibly using the Android keyboard from the Android source: https://android.googlesource.com/platform/packages/inputmethods/LatinIME

Alternatively there is a current discussion here but without a complete solution: http://groups.google.com/group/android-developers/browse_thread/thread/17210d784766602d

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Laxmeena
  • 780
  • 1
  • 5
  • 27
0

Use this property for your EditText:

android:imeOptions="actionNone"  

It will always keep your native keyboard open/visible.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
VVB
  • 6,526
  • 7
  • 39
  • 71