0

i have a edittext for filtering list. And my problem is that when i click on edittext the keyboard doesn't show up and when i press enter it just wont close.

I'm filtering using this code:

adapt = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,veik);
    lv.setTextFilterEnabled(true);
ed.addTextChangedListener(new TextWatcher() {

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

            }

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

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                // veikali.this.veik.getFilter().filter(s);
                 adapt.getFilter().filter(s);
            }
        });

          ed.setClickable(true);

Can you please tell me how can i show keyboard when i click on edittext and hide it when i press enter?

CMA
  • 2,758
  • 5
  • 28
  • 40
J1and1
  • 920
  • 3
  • 12
  • 25

3 Answers3

1

If you are using a TouchScreen phone, on touching the edittext the SoftKeyboard would come up. As for the second part of your query try the following:

ed.setOnKeyListener(new View.OnKeyListener()
    {

        @Override
        public boolean onKey(View editView, int keyCode, KeyEvent event)
        {
            Context mContext = MyClass.this;
            if( keyCode == KeyEvent.KEYCODE_ENTER ){
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(ed.getWindowToken(),0);
                return true;
            }
            return false;
        }
    })
Arun George
  • 18,352
  • 4
  • 28
  • 28
1

This seems like a lot of extra work. I don't every remember having to give this functionality to my edittexts because it should be doing it by default.

Are you sure that the edittext to focusable and there isn't some type of view blocking it? If your using in a list view you may want to check out this thread Focusable EditText inside ListView

Community
  • 1
  • 1
Frank Sposaro
  • 8,511
  • 4
  • 43
  • 64
0

as simple solution, try to add the following attribute for activity's tag in AndroidManifest.xml :

android:windowSoftInputMode="stateVisible|adjustResize"

check this documentation.

Eng. Samer T
  • 6,465
  • 6
  • 36
  • 43